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