Codeigniter查询错误

时间:2013-07-23 03:03:46

标签: php mysql sql codeigniter

使用时:

$cols_string = implode(',',$cols_array;
$query = "INSERT INTO TB_BATs (col1, col2, col3  VALUES $cols_string "      
$this->db->query($query);

我得到"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 "

接下来是SQL查询,但是当我在PHPMYADMIN中复制查询时,它工作正常,如果将其复制到$query字符串中它也可以正常工作,只有在使用$cols_string <时才出现问题/ p>

1 个答案:

答案 0 :(得分:6)

您忘记关闭括号

$query = "INSERT INTO TB_BATs (col1, col2, col3) VALUES ($cols_string)"

还在这里: $cols_string = implode(',',$cols_array);