Codeigniter - SQL错误。让我疯狂
问题描述:
这是我的代码:Codeigniter - SQL错误。让我疯狂
$ child = $ this-> getDetails($ row ['ParentOf_Id']);
这是在调用一个函数调用getdetails另一个功能:
功能getDetails($ child_id = NULL,$限制= 20){
// select all the fields in the children table
$this->db->select(castedColumns($this->children_table, $this->db));
//where the id is the child id
$q = $this->db->get_where($this->children_table, 'id='.$child_id);
//store results array in details
$details = $q->row_array();
然后我得到下面的SQL错误:
数据库出错 错误号:
附近有语法错误 '='。
SELECT CAST(文字AdditionalNotes)作为AdditionalNotes,CAST(DisabilitiesNotes文本)作为DisabilitiesNotes,出生日期,msrepl_tran_version儿童WHERE ID =
id没有追加?为什么?
一直在推动我坚果,因为,当我做echo $ child_id;在将它传递到SQL之前,我得到了子Id。
答
尝试:
$this->db->select(castedColumns($this->children_table, $this->db));
$q = $this->db->get_where($this->children_table, array('id' => $child_id));
$details = $q->row_array();
答
我猜想,$ child_id为空,否则它会显示在数据库中的错误查询。尝试打印$ child_id,看看它是否真的这将意味着
$child = $this->getDetails($row['ParentOf_Id']);
$行[“ParentOf_Id”]为空空。
得到它的工作,$ child_id = null更改为$ child_id和mikhail解决方案似乎已经做到了。干杯。 – bobo2000 2012-03-16 17:54:15