I have a system running on Apache with PHP 5.5 and a database SQLSERVER 2012 Express.
After installed the extension "php_sqlsrv_55_ts" and add the extension in php.ini, i install the ODBC controller for my SO (Windows 8.1).
Well, im pretty sure i installed everything right.
When i run a php script, it returns the output var O.K (example in the end). But after a time, this script "fail" and dont return anything. Not error message, not var output, anything. This happens intermittently. Sometimes is work O.K, sometimes fail.
As you can see, i set a default var $outputVar to -1.
After the script execute the Procedure, i expected this overwrite my $outputVar, and this work O.K. The problem is, sometimes the script run without errors, but dont return anything, in consequence the $outputVar never is overwrite and the default value still is -1.
This happened with all my procedures, even with the most simplest.
This happens randomdly.
My PHP script.
$serverName = "xx.xx.xx.xx\SQLEXPRESS, 1433";
$connectionInfo = array(
"Database" => "xxxxx",
"UID" => "xxxxx",
"PWD" => "xxxxx",
'CharacterSet' => 'UTF-8',
);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn) {
echo "ok.";
} else {
echo "error";
}
$outputVar = 'ANDRONICO'; // this is default value.
$parameters = array(
array($outputVar, SQLSRV_PARAM_OUT),
);
$query = '{CALL TEST_SP(?)}';
$stmt = sqlsrv_query($conn, $query, $parameters);
sqlsrv_next_result($stmt);
if ($stmt === false) {
$errors = sqlsrv_errors();
var_dump($errors);
}
var_dump($outputVar); // this var is overwrite by SQLSRV library.
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
My Stored procedure return a random number from 1 to 1000
CREATE PROCEDURE [dbo].[test_1]
(
@ret_cod int OUTPUT
)
As
BEGIN TRY
SET NOCOUNT On
SET @ret_cod = (SELECT ROUND(((999) * RAND() + 1), 0));
END TRY
BEGIN CATCH
SET @ret_cod = (SELECT ERROR_NUMBER() AS ErrorNumber)
END CATCH