![带有PDO的多个插入[重复],第1张 带有PDO的多个插入[重复],第1张](/aiimages/%E5%B8%A6%E6%9C%89PDO%E7%9A%84%E5%A4%9A%E4%B8%AA%E6%8F%92%E5%85%A5%5B%E9%87%8D%E5%A4%8D%5D.png)
几件事:
请参阅调整后的
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();}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)