当前位置:Gxlcms > PHP教程 > MYSQL写入异常讯息

MYSQL写入异常讯息

时间:2021-07-01 10:21:17 帮助过:26人阅读

MYSQL 写入错误讯息

$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
请问哪里写错了?
------解决思路----------------------
字段列数和值的数量不对应
看你数据,你可能是要批量插入
先将你的 sql 输出看一下,应该是你组织sql错了


------解决思路----------------------
我要你贴出
$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 是空数组

人气教程排行