php PDO insert batch multiple rows with placeholders

前端 未结 5 1446
失恋的感觉
失恋的感觉 2020-12-01 10:53

I am looking to do multiple inserts using PHP PDO.

The closest answer I have found is this one

how-to-insert-an-array-into-a-single-mysql-prepared-st

5条回答
  •  没有蜡笔的小新
    2020-12-01 11:11

    Move execute inside of the loop.

    $stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
    foreach($valuesToInsert as $insertRow)
    {
        $stmt->execute($insertRow);    
    }
    

    If you experience any problems with this such recommended way, you have to ask a question, describing these certain problems.

提交回复
热议问题