Last active
March 17, 2016 07:04
-
-
Save PakL/97abbb0767df3f42ba51 to your computer and use it in GitHub Desktop.
msphpsql crash on fetching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mssql_resource = sqlsrv_connect(MSSQL_HOST, array("Database" => MSSQL_DATABASE, "UID" => MSSQL_USER, "PWD" => MSSQL_PASSWORD, "CharacterSet" => "UTF-8")); | |
if(is_resource($mssql_resource)) { | |
// Query WITHOUT parameters and DEFINED fetchType: Works fine | |
$stmt = sqlsrv_prepare($mssql_resource, "SELECT TOP 5 * FROM [table]"); | |
if($stmt !== false) { | |
if(sqlsrv_execute($stmt)) { | |
while(is_array($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))) { | |
var_dump($row); | |
} | |
} else print("exec failed"); | |
} else print("stmt failed"); | |
// Query WITHOUT parameters and UNDEFINED fetchType: Works fine | |
$stmt = sqlsrv_prepare($mssql_resource, "SELECT TOP 5 * FROM [table]"); | |
if($stmt !== false) { | |
if(sqlsrv_execute($stmt)) { | |
while(is_array($row = sqlsrv_fetch_array($stmt))) { | |
var_dump($row); | |
} | |
} else print("exec failed"); | |
} else print("stmt failed"); | |
// Query WITH parameters and DEFINED fetchType: Works fine | |
$colval = 10; | |
$stmt = sqlsrv_prepare($mssql_resource, "SELECT TOP 5 * FROM [table] WHERE [col] = ?", array(&$colval)); | |
if($stmt !== false) { | |
if(sqlsrv_execute($stmt)) { | |
while(is_array($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))) { | |
var_dump($row); | |
} | |
} else print("exec failed"); | |
} else print("stmt failed"); | |
// Query WITH parameters and UNDEFINED fetchType: Crashes PHP with exit code 255 | |
$colval = 10; | |
$stmt = sqlsrv_prepare($mssql_resource, "SELECT TOP 5 * FROM [table] WHERE [col] = ?", array(&$colval)); | |
if($stmt !== false) { | |
if(sqlsrv_execute($stmt)) { | |
while(is_array($row = sqlsrv_fetch_array($stmt))) { | |
var_dump($row); | |
} | |
} else print("exec failed"); | |
} else print("stmt failed"); | |
sqlsrv_close($mssql_resource); | |
} else die("connection failed"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment