duanqiang9212 2016-10-07 16:33
浏览 53
已采纳

Codeigniter:在坏列引起的非对象上调用成员函数result_array()?

I'm having an issue in codeigniter to return a result set. When I'm avoiding 1 column in my select, the result is correct. But when i want to include the column (description) then i get the error and my result-set is corrupt. Anyone knows how to solve this issue. The column has soms records with characters like &,'/... I might think that this causes the problem.

some details:

'char_set' => 'UTF-8',
'dbcollat' => 'Latin1_General_100_CS_AS',

I already tried to change these parameters without success.

EDIT Code added:

get and get_by function.

public function get($id = NULL, $single = FALSE) {

    if($id != NULL){
        $this->db->where($this->_primary_key, $id);
        $method = 'row';
    }
    elseif($single == TRUE){
        $method = 'row';
    }
    else{
        $method = 'result';
    }

    if($_order_by != ''){
        if(!count($this->db->ar_orderby)){
            $this->db->order_by($this->_order_by);
        }

    }
    //$query = $this->db->query("Select Description from items WHERE Company = 'MINITFR'");

   // $array = $query->result_array();
   // return 'test';
   // var_dump($this->db->get_compiled_select($this->_table_name));
    return $this->db->get($this->_table_name)->result_array();
  // return $this->db->get($this->_table_name)->$method();
}

public function get_by($where, $single = FALSE) {
    $this->db->where($where);   
    return $this->get(NULL,$single);
}

function in controller:

public function show_items(){

    $this->load->model('item_m');
    $this->data['ajax_req'] = TRUE;
    $where = "Company = '".$this->session->userdata('company')."'";
    $this->data['item_list'] = $this->item_m->get_by($where,FALSE);
    $this->load->view('pages/details/components/item_list', $this->data);
}
  • 写回答

1条回答 默认 最新

  • doubu0897 2016-10-07 16:58
    关注

    use this one:

    return $this->db->get('table_name')->result_array();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?