PHP 5.4.14 SQL Server 2012 / SQL Client 2012 Windows 2008 R2
I have a function (simplified version) that I call to run an SQL query. It works correctly: connects to the database; launches the request and receives a valid resource. The problem is that the returned resource is null ...
function squeal($query) { $serverName = "XXXXXXXX\SQLEXPRESS"; $uid = "private"; $pwd = "private"; $connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd, "Database"=>"DBname"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "Unable to connect.</br>"; die( print_r(sqlsrv_errors(), true)); } $result = sqlsrv_query( $conn, $query, array(), array("Scrollable"=>"buffered")); if( $result === false ) { echo "Error in executing query.</br>"; die( print_r(sqlsrv_errors(), true)); } echo("Resource=".intval($result)."</br>"); echo("Has rows=".sqlsrv_has_rows($result)."</br>"); return $result; } $tsql = "SELECT id FROM mytable"; $fred = squeal($tsql); echo("Resource=".intval($fred)."</br>"); echo("Has rows=".sqlsrv_has_rows($fred)."</br>");
It gives the following result ...
Resource=8 Has rows=1 Resource=8 Warning: sqlsrv_has_rows(): 8 is not a valid ss_sqlsrv_stmt resource in <path> on line 85 Has rows=
SQL works correctly and returns a valid resource. Upon returning from the function, he knows that Resource # 8 has been transferred (in this case), but it is empty. I use a similar method for MySQL, which works fine. My entire intranet application relies on the ability to call a function to run a request and return a resource.
Does the resource "die" when exiting the function in sqlsvr / ODBC? of course not.
I spent a couple of days clearing Google of the answers, but it can make the SQL server work outside the function. I would appreciate any suggestions.
Greetings
source share