MYSQL 写入错误讯息
程序员文章站
2024-02-06 18:10:58
...
$value = array ();foreach ($all as $cust) { $value[] = " ('{$cust['id']}', '{$cust['last']}') ";} echo $query = " insert into cust (cust_id,last) values ". implode(", ", $value);$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 1
请问哪里写错了?
回复讨论(解决方案)
values 后面加括号,把插入内容括起来
出现这个错误...
Column count doesn't match value count at row 1
字段列数和值的数量不对应
看你数据,你可能是要批量插入
先将你的 sql 输出看一下,应该是你组织sql错了
你都 echo $query.....
为什么不贴出来看看?
如果数据本身没问题,应该不会出错的
to jam00 他是要生成这样的指令,有问题吗?
insert into cust (cust_id,last) values ('1','2'), ('3','4')
echo $query 印出
insert into cust (cust_id,last) values ()Column count doesn't match value count at row 1
我要你贴出
$value = array (); foreach ($all as $cust) { $value[] = " ('{$cust['id']}', '{$cust['last']}') ";} echo $query = " insert into cust (cust_id,last) values ". implode(", ", $value);
的结果,你贴了吗?
如果是 insert into cust (cust_id,last) values ()
那就是说 $all 是空数组
下一篇: 用文本作数据处理_PHP