使用时:
$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>
答案 0 :(得分:6)
您忘记关闭括号
$query = "INSERT INTO TB_BATs (col1, col2, col3) VALUES ($cols_string)"
还在这里:
$cols_string = implode(',',$cols_array);