我正在使用MSSQL服务器进行Symfony 4项目(不是最佳选择,而是公司的决定)。
使用命名变量时遇到问题。
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near ':'.
例如:
$query->where("status = :status");
我们通过setParameter()应用值
$query->setParameter('status', $status);
我们收到语法错误。我试图用引号本身存储引号,以确保不是这种情况,但是它返回相同的错误。如果我将命名变量替换为ex:“ ACTIVE”,则按预期运行。我还用getSQL()打印了sql,并直接在SQL Management Studio中对其进行了测试,这也很好用。
调试该语句很困难,我正在考虑是否需要创建连接包装器类并进行操作以支持MSSQL,但是在进行扩展之前,也许你们中的有些人有想法?
完整的错误响应:
An exception occurred while executing 'SELECT U.CIID AS ciid, U.USERID as userid, U.FIRSTNAME as firstname, U.MIDDLENAME as middlename, U.LASTNAME as lastname, ACI.emailid as email, U.JOBTITLE as position, ACI.landline as phone_local, ACI.mobile as phone_mobile, P.ATTRIBUTE_1801 as phone_cisco FROM SDUSER U INNER JOIN AaaUser AU ON U.USERID=AU.USER_ID INNER JOIN People P ON U.CIID=P.CIID INNER JOIN AaaUserContactInfo AUCI ON AU.USER_ID=AUCI.USER_ID INNER JOIN AaaContactInfo ACI ON AUCI.CONTACTINFO_ID=ACI.CONTACTINFO_ID WHERE U.STATUS=:status':
SQLSTATE [42000, 102]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near ':'.
SQLSTATE [42000, 8180]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared. (500 Internal Server Error)
如您所见,看来命名参数正在强制对mssql无法接受的整个sql进行换行。
MSSQL 2012 PHP 7.1.3 Symfony 4 教义2
答案 0 :(得分:0)
也许您需要将以下代码放在下面:
ini_set('mssql.charset', 'UTF-8');