<分区>
我查看了所有其他关于在 PDO 中插入数组的帖子,但一直无法弄清楚具体如何操作。我要拿这个:
$images_ar =
Array
(
[0] => Array
(
[0] => 100
[1] => Lips
[2] => 50
[3] => 50
[4] => 127
[5] => 257
[6] => 9998
[7] => 70
[8] => xxx
)
[1] => Array
(
[0] => 103
[1] => Ball
[2] => 117
[3] => 114
[4] => 128
[5] => 44
[6] => 9997
[7] => 70
[8] => xxx
)
[2] => Array
(
[0] => 104
[1] => Sun
[2] => 94
[3] => 91
[4] => 48
[5] => 277
[6] => 9996
[7] => 70
[8] => xxx
)
)
然后执行 PDO 插入,其中 [0] = image_id 和 [9] = avatar_id。
利用其他帖子,到目前为止,我有这个:
$images_ar = array_chunk($ar, 9);
$handler->beginTransaction();
foreach($images_ar as $row){
$question_marks[] = "('',?,?,?,?,?,?,?,?)";
}
$query = $handler->prepare ("INSERT INTO avatars (ID, img_id, title, width, height, top, left, zindex, userid, avatar_id) VALUES " . implode(',', $question_marks);
$query->execute($ar);
$handler->commit();
错误:
fatal error :消息为“SQLSTATE[42000]”的未捕获异常“PDOException”:语法错误或访问冲突:1064 您的 SQL 语法有错误;查看与您的 MySQL 服务器版本对应的手册,了解在 'left, zindex, userid, avatar_id) 附近使用的正确语法 VALUES ('',?,?,?,?,?,?,?,?),(' ',?,?,?,?,?,?,?,?' 在 ...\save.php:52 的第 1 行
堆栈跟踪:0 ...\save.php(52): PDO->prepare('INSERT INTO ava...')
1 {主要}
在 52
我走在正确的轨道上吗?
谢谢大家! =D