gpt4 book ai didi

php - zend 框架 : how to prepare and execute WHERE IN clause?

转载 作者:可可西里 更新时间:2023-11-01 00:36:31 27 4
gpt4 key购买 nike

我想准备一个在循环内使用的语句。当我尝试执行该语句时,我在日志中看到一条错误消息,提示“参数编号无效:未绑定(bind)任何参数”。

我的代码有什么问题?

$itemSelectSql = "SELECT * FROM `tblItems` WHERE `itemID` IN (?)";
$itemSelectStmt = new Zend_Db_Statement_Mysqli($this->db_ro, $itemSelectSql);
while () {
...
$itemIds = array();
// populate $itemIds array
...
$itemSelectStmt->execute(array($itemIds));
}

编辑:

我认为我的设置中可能存在错误,这解释了为什么我尝试的任何操作都失败了。我看到了这个:

PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, 
class 'PDOStatement' does not have a method 'bind_param' in
/var/www/lib/Zend/Db/Statement/Mysqli.php on line 204

编辑:

我使用了错误的适配器。应该是 Zend_Db_Statement_Pdo :-)

感谢您的回复。

最佳答案

? 不能用数组替换,它必须用标量替换(感谢评论指出这并不总是意味着字符串......我脑子放屁结尾)。让我知道这是否更好:

$itemSelectSql = "SELECT * FROM `tblItems` WHERE `itemID` IN ";
while () {
...
$itemIds = array();
// populate $itemIds array
...
// we need to have the same number of "?,"'s as there are items in the array.
// and then remove final comma.
$qs = rtrim(str_repeat("?,", count($itemIds)),',');
// create a statement based on the result
$itemSelectStmt =
new Zend_Db_Statement_Mysqli($this->db_ro, "$itemSelectSql ($qs)");
// bind to each of those commas.
$itemSelectStmt->execute($itemIds);
}

关于php - zend 框架 : how to prepare and execute WHERE IN clause?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6305738/

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