gpt4 book ai didi

php - 在 Propel 中使用 WHERE IN 和准备好的 SQL 语句

转载 作者:搜寻专家 更新时间:2023-10-31 21:16:44 27 4
gpt4 key购买 nike

在我正在使用 Propel 处理数据库的系统中,我正在准备一个需要接受不同 WHERE IN 条件的原始查询。

我想做的一个简单例子是:

$c = Propel::getConnection();
$q = $c->prepare("SELECT foo FROM bar WHERE blah IN(:ids)");
$q->execute(array(':ids' => array(1, 2, 3, 4, 5)));

显然,这对我不起作用。我也尝试过使用 implode(',' array(1, 2, 3, 4, 5)) 作为我的 ':ids' 参数,这也不起作用。第一种方法提示必须接受数组,第二种方法提示将字符串与整数进行比较。

是否有适当的方法将值数组传递给 WHERE IN 的查询?我不想对其进行硬编码,因为这意味着要为循环的每次迭代做好准备。

请注意,我实际上没有选择创建条件并改为使用 doSelect 的选项,因为查询实际上比此处给出的示例复杂得多,我严重怀疑我是否可以那样构建它。

非常感谢!

最佳答案

You cannot use a named parameter marker of the same name twice in a prepared statement. You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement.

PDO::prepare

Propel uses PDO

Propel site

关于php - 在 Propel 中使用 WHERE IN 和准备好的 SQL 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6945434/

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