gpt4 book ai didi

php - 使用准备好的语句进行多次插入

转载 作者:行者123 更新时间:2023-11-29 12:08:50 25 4
gpt4 key购买 nike

我想在我的数据库中插入 5 个行,但是以下

$qry = $db->prepare('INSERT IGNORE INTO table (foo, bar) VALUES 
(?,?),
(?,?),
(?,?),
(?,?),
(?,?)');
$qry->execute(array(
array($foo1, $bar),
array($foo2, $bar),
array($foo3, $bar),
array($foo4, $bar),
array($foo5, $bar)
));

给我这个错误

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

我应该怎么做才能让它发挥作用?

最佳答案

删除execute()中多余的数组

$qry = $db->prepare('INSERT IGNORE INTO table (foo, bar) VALUES 
(?,?),
(?,?),
(?,?),
(?,?),
(?,?)');
$qry->execute(array(
$foo1, $bar,
$foo2, $bar,
$foo3, $bar,
$foo4, $bar,
$foo5, $bar
));

关于php - 使用准备好的语句进行多次插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31047089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com