gpt4 book ai didi

mysql - 如何使用 Zend DB 做 MySQL IN 子句?

转载 作者:可可西里 更新时间:2023-11-01 06:31:50 25 4
gpt4 key购买 nike

我正在尝试获取我使用 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));

当我使用 $this->dbSelect__toString() 方法时,我得到

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 子句成为

product_ref_id IN ('10', '12')

product_ref_id IN (10, 12)

使用 Zend DB 准备好的语句,以便我可以获取产品 ID 数组中包含的所有行?

最佳答案

不要内爆数组,只是传递它:

->where('product_ref_id IN (?)', $product_ids);

关于mysql - 如何使用 Zend DB 做 MySQL IN 子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8682520/

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