简体   繁体   中英

insert into multiple rows PDO

i am struggling with the code to insert into multiple rows.

but ended up getting warnings

$rows = array(1,2,3,4,5,6)

$stmt = $connect->prepare("INSERT INTO t_worker_history (uid) VALUES (?)");
foreach($rows as $insert) {
    $stmt->execute($insert);
}

: PDOStatement::execute() expects parameter 1 to be array, string given in :PDOStatement :: execute()期望参数1为数组,字符串形式为

As the message says, the first parameter needs to be an array, so just put the $insert value into one:

$stmt->execute(array($insert));

See the manual . The reason the parameter needs to be an array is to allow for multiple parameters to be bound to placeholders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM