0 and field2 IN (:buzzGroups) and active = 1"; $arrPara-6ren">
gpt4 book ai didi

php - 将 nvarchar 值 '10,12' 转换为数据类型 int 时转换失败

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

$sSql = "SELECT * FROM table1 where field1 > 0 and field2 IN (:buzzGroups) and active = 1";
$arrParams = array('buzzGroups' => $vBuzzGroups);
$stmt = $this->tableGateway->getAdapter()->createStatement($sSql);
$stmt->prepare($sSql);
$data = $stmt->execute($arrParams);

这是 $vBuzzGroups = '10,12'; 的值

当我只传递单个值时它会起作用但是当我尝试使用多个值时..逗号分隔的值会给我错误,

Conversion failed when converting the nvarchar value '10,12' to data type int

有人遇到过这个问题吗?

最佳答案

使用 implode() 函数拆分值。

试试这个更新后的代码

$arrParams = array('buzzGroups' => $vBuzzGroups);
$sSql = "SELECT * FROM table1 where field1 > 0 and field2 IN
(".implode(',',$arrParams).") and active = 1";

关于php - 将 nvarchar 值 '10,12' 转换为数据类型 int 时转换失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31650359/

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