gpt4 book ai didi

php - 在不使用引号的情况下在查询中传递字符串 ''

转载 作者:可可西里 更新时间:2023-11-01 07:18:35 26 4
gpt4 key购买 nike

我有这个查询代码:

$conditions[]=array('codiceBiblio IN (?)'=> $tot);

其中 $tot 是一个字符串(例如:2345,5657,4565,5678)。
在这种情况下,查询将是:

SELECT [...] WHERE codiceBiblio IN ('2345,5657,4565,5678')

但它只会返回第一条记录。

所以应该是:

SELECT [...] WHERE codiceBiblio IN (2345,5657,4565,5678)

我该怎么做?


如何构建查询

我有这个查询代码:

// General Query
$conditions = array(
'editore LIKE' => "%$e%",
'titolo LIKE' => "%$t%"
);

然后我用用户的选择填充 $conditions,例如:

if ($anno&&$anno2)
$conditions[] = array('anno BETWEEN ? AND ?' => array($anno,$anno2));

if (isset($menu)&&$menu!='')
$conditions[]=array('classe LIKE' => "%$menu%");

最佳答案

只需使用数组并省略 IN() 子句。手册 ( Complex Find Conditions ) 提供了这个例子:

array('Company.status' => array('inactive', 'suspended'))

... 生成以下 SQL:

`Company`.`status` IN ('inactive', 'suspended')

如果 $tot 是像 2345,5657,4565,5678 这样的字符串,您需要先将其 explode()

免责声明:这适用于 Cake 2,不确定 1.2。

关于php - 在不使用引号的情况下在查询中传递字符串 '',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15112779/

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