几件事:
- 在
for
循环内删除第二个prepare语句 - 将绑定的参数添加到
VALUES()
sql语句中 $images
使用for
循环迭代器索引数组或使用foreach
请参阅调整后的
for循环:
$stmt = $this->db->prepare("INSERT INTO images (category_id, dir_image) VALUES (:category_id, :dir_image)");$stmt->bindParam(":category_id" ,$lastId); $stmt->bindParam(":dir_image", $image);for ($i = 0; $i < count($images); $i++){ $image = $images[$i]; $stmt->execute();}或者使用
foreach循环 (假设是一维数组) :
$stmt = $this->db->prepare("INSERT INTO images (category_id, dir_image) VALUES (:category_id, :dir_image)");$stmt->bindParam(":category_id", $lastId); $stmt->bindParam(":dir_image", $item);foreach ($images as $item){ $stmt->execute();}

![带有PDO的多个插入[重复] 带有PDO的多个插入[重复]](http://www.mshxw.com/aiimages/31/416745.png)
