Reputation: 334
I have recently switch to SQLSRV from ODBC to connect MS SQL 2008 from PHP. There is a strange issue with PRINT function in stored procedure. IF PRINT function display more than approximately 700 characters, "HTTP Error 500.0 - Internal Server Error" message is return.
Following are list of tools I am using:
Following is the code PHP CODE:
<?php
$link = sqlsrv_connect( 'dbname\instance2008', array( "UID"=>'UID',"PWD"=>'PWD', "Database"=>'Database_name',"CharacterSet" => "UTF-8", "MultipleActiveResultSets" => 0));
if(!$link) die( print_r(sqlsrv_errors(), true));
sqlsrv_configure('WarningsReturnAsErrors', 0);
$sql = "EXEC spa_i18n_test";
$result = sqlsrv_query($link, $sql);
if(!isset($result)){
error_reporting(2047);
}
while( $row = sqlsrv_fetch_array( $result)){
echo $row[0] . ": " . $row[1] . "<br />";
}
?>
SCRIPT FOR stored procedure.
Create proc spa_i18n_test
AS
SET NOCOUNT ON
print '2222222222222111111111111111112dddddddddddddd2222222222
222111111111111111112dddddddddddddd2222222222222111111
111111111112dddddddddddddd222222222222211111111111111111
2dddddddddddddd222222222222211111111111111122222222222221
11111111111111112dddddddddddddd222222222222211111111111111
1112dddddddddddddd2222222222222111111111111111112dddddddddd
dddd2222222222222111111111111111112dddddddddddddd22222222222
221111111111111112222222222222111111111111111112dddddddddddd
dd2222222222222111111111111111112dddddddddddddd2222222222222
111111111111111112dddddddddddddd2222222222222111111111111111
112dddddddddddddd2222222222222111111111111111222222222222211
1111111111111112ddddddddd22222wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwww'
select '1' a, '2' b
I have tried the solution given in http://support.microsoft.com/kb/269412 but sadly it didn't work for me.
Please share some work around.
Upvotes: 1
Views: 1111
Reputation: 11
This issue still exists in PHP 7.0.11 using sqlsrv driver 4.1.2 (x64) when the character count is greater than about 5200 characters.
sqlsrv_configure('WarningsReturnAsErrors', 0);
is important but doesn't fix the problem.
My workaround was to add a bit parameter to the stored procedure in question to optionally suppress the problem output due to PRINT commands.
Upvotes: 1
Reputation: 121659
I'm not sure what's causing your "700" limit. But even so, "PRINT" still has a limit of 8000.
One workaround is to split the "print" text into smaller chunks. For example:
Upvotes: 1
Reputation: 96
SQLSRV does not allowed to execute the print message result the error. Use
sqlsrv_configure('WarningsReturnAsErrors', 0);
just before
sqlsrv_query()
function to suppress the error. ie disabled only, but not ignore at database layer.
Upvotes: 1