如何使用Zend DB进行MySQL IN子句? [英] How to do MySQL IN clauses using Zend DB?
本文介绍了如何使用Zend DB进行MySQL IN子句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Zend Framework 1.11中的整数数组来获取行。
I'm trying to fetch rows that are in an array of integers that I have using Zend Framework 1.11.
$this->dbSelect
->from($table_prefix . 'product_link')
->joinLeft($table_prefix . 'product_link_name', $table_prefix . 'product_link.product_link_name_ref_id = ' . $table_prefix . 'product_link_name.product_link_name_id')
->where('product_ref_id IN (?)', implode(', ', $product_ids));
当我使用 __ toString()
的 $ this-> dbSelect
,我得到
SELECT `phc_distrib_product_link`.*,
`phc_distrib_product_link_name`.*
FROM `phc_distrib_product_link`
LEFT JOIN `phc_distrib_product_link_name`
ON phc_distrib_product_link.product_link_name_ref_id = phc_distrib_product_link_name.product_link_name_id
WHERE (product_ref_id IN ('10, 12'))
这只返回满足product_ref_id = 10.
如何获得IN子句
This only returns rows satisfying the condition where product_ref_id = 10. How can I get the IN clause to be
product_ref_id IN ('10', '12')
或
product_ref_id IN (10, 12)
使用Zend DB准备的语句,所以我可以获取内部包含的所有行产品ID数组?
using Zend DB prepared statements so I can fetch all rows contained inside the product id array?
推荐答案
不要打破数组,只需传递:
Don't implode the array, just pass it:
->where('product_ref_id IN (?)', $product_ids);
这篇关于如何使用Zend DB进行MySQL IN子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文