作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在我正在使用 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.
Propel uses PDO
关于php - 在 Propel 中使用 WHERE IN 和准备好的 SQL 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6945434/
我是一名优秀的程序员,十分优秀!