sql server - Trouble returning MSSQL query results from PHP function -
i'm getting strange error when attempting return results of working sqlsrv_query function call.
i have set up:
function test($someinput, &$someoutput) { //set $dbc , $dbcoptions //generate tsql $params = array(); $stmt = sqlsrv_query($dbc, $tsql, $params, $dbcoptions); $someoutput = $stmt; return $stmt; } $outputvar; $results = test($inputvar, $outputvar); //---error being thrown here $rows = sqlsrv_num_rows($results); //$rows2 = sqlsrv_num_rows($outputvar); //---error being thrown here
in both lines (doesn't matter use), i'm getting error in php-errors.log
file saying
php warning: sqlsrv_num_rows(): 2 not valid ss_sqlsrv_stmt resource in e:\inetpub\wwwroot\directory\searchtest.php on line 58
which searchtest.php
file i'm working on , line 58 have error-producing code.
why can not pass query results function this?
as per op's wish mark answered, comment (slightly modified) answer:
this sounds scope issue.
try passing $dbc
function (best), or (not recommended) make global $dbc;
in function.
Comments
Post a Comment