尝试运行以下代码时,
$query = "INSERT INTO check (name, number) values ";
$query .= implode(',', $read_data);
$stmt = $this->pdo->prepare($query);
$stmt->execute();
其中$read_data
是一个数组,其值为('aaa','000'),('bbb','001'),('ccc','002')
我收到错误语法错误或访问冲突
Syntax error or access violation: 1064 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 'check (name, number) values ('aaa','000'),('bbb','001' at line 1
答案 0 :(得分:1)
将$query = "INSERT INTO check ..."
更改为$query = "INSERT INTO `check` ..."
。 CHECK
是SQL中的保留字。
答案 1 :(得分:0)
这种类型的数组会,但字符串最后需要单引号和分号。
$read_data = array("('aaa','000')","('bbb','001')","('ccc','002')");
$query = "INSERT INTO `check` (name, number) values ";
$query .= implode(',', $read_data).";";
echo $query;
给我:
INSERT INTO `check` (name, number) values ('aaa','000'),('bbb','001'),('ccc','002');