我的$POST
值为“WYNN'S”。当我创建通过Yii2框架SQL查询:php post:用sqlserver查询替换单双引号的单引号
$vendor = (new Query()) ->select('VendorNo') ->distinct() ->from('Pm_Item i') ->innerJoin('[PurchPrice] [p]', 'p.ItemNo = i.ItemNo AND p.CompanyKey = i.CompanyKey') ->where($condition)->all();
我得到一个错误:
Incorrect syntax near 'S'. The SQL being executed was: SELECT DISTINCT [TopCode] FROM [PM_Item] WHERE Brand IN('WYNN'S')
我怎么能代替 '永利' 与 '永利' 的”使用PHP?
UPDATE:
$condition = '';
$i = 0;
foreach ($filters as $filter) {
if (isset($filter['selected'])) {
if (strpos($filter['selected']['value'], "'") !== false) {
$filter['selected']['value'] = str_replace("'", "''", $filter['selected']['value']); //preg_replace('/\'/', '\'\'', $filter['selected']['value']);
}
if ($i != 0 AND $filter['selected']['value'] != '') {
$condition .= ' AND i.' . $filter['column'] . ' = \'' . $filter['selected']['value'] . '\'';
} elseif ($filter['selected']['value'] != '') {
$condition .= 'i.' . $filter['column'] . ' = \'' . $filter['selected']['value'] . '\'';
}
$i++;
}
}
你可以显示你创建这个sql查询的代码吗? – Jerodev
我使用Yii2框架:'$ vendor =(new Query()) - > select('VendorNo') - > distinct() - > from('Pm_Item i') - > innerJoin('[PurchPrice] [p]','p.ItemNo = i.ItemNo AND p.CompanyKey = i.CompanyKey') - > where($ condition) - > all();' – Lyuba
https://stackoverflow.com/a/130323/7926064 – BNT