I think I have found a bug in the SQLSRV driver. I have tested this in v1.1 and v2.0.
If the stored procedure contains a PRINT statement before the SELECT statement, the query will fail and the value to be printed will appear in the errors array.
For example:
The stored procedure is defined as:
CREATEPROCEDURE dbo.camtest_sps ASPRINT'hello'SELECT * FROM product WHERENAMElike'Am%'
The PHP code is:
$connectionInfo = array('UID'=>$TEST_MSSQL_USERNAME,'PWD'=>$TEST_MSSQL_PASSWORD,'Database'=>'test'); $connectMSSQL = sqlsrv_connect($TEST_MSSQL_DATABASESERVER, $connectionInfo); $result = sqlsrv_query($connectMSSQL, 'camtest_sps');if ($result === false) { $errors = sqlsrv_errors(); print_r($errors); }
The output from the PHP script is:
Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]hello [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]hello ) )
If the PRINT statement in the stored procedure appears after the SELECT statement or is commented out, the query is successful.
I hope that a SQLSRV developer can examine this and confirm whether this is a bug or give direction if there is something I can do so that a SP with PRINT statements does not fail.