$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/