带有PDO的多个插入[重复]

带有PDO的多个插入[重复],第1张

带有PDO的多个插入[重复]

几件事:

  1. for
    循环内删除第二个prepare语句
  2. 将绑定的参数添加到
    VALUES()
    sql语句中
  3. $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();}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5044667.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-15
下一篇2022-11-15

发表评论

登录后才能评论

评论列表(0条)

    保存