我有一个使用PDO查询mssql数据库的PHP函数。在我的SELECT查询中,我将ANSI_NULLS和ANSI_WARNINGS设置为ON,然后紧接着我的SELECT。当我尝试加载这个函数调用的页面时,我得到了一个500的错误,并且在我的php错误日志中得到了一条信息。
错误信息:
Next exception 'Zend\Db\Adapter\Exception\InvalidQueryException' with message 'Statement could not be executed (HY000 - 20018 - Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the conn in /Adapter/Driver/Pdo/Statement.php on line 244
SQL查询:
function getEmployees() {
global $mssql_employees;
$sql = "
SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
SELECT * FROM employeeList";
$statement = $mssql_employees->query($sql);
$result = $statement->execute();
$r = [];
foreach ($result as $row){
$r[] = $row;
}
return $r;
}