I'm encountering a strange issue, where sqlsrv_query() returns a valid statement resource, but sqlsrv_fetch_array() subsequently returns false. I tested my query ($q) in MS SQL Server Management Studio, so I know it returns a result with a certain number of rows. The code I have is...
$r = @sqlsrv_query($dbcMssql, $q, array(), array('Scrollable'=>'static')); // works
$rowCount = sqlsrv_num_rows($r); // this shows there are correct number of rows
$row = sqlsrv_fetch_array($r, SQLSRV_FETCH_ASSOC); // $row is FALSE
I'm using the same bit of a code on another MSSQL database, and it is working without any problem. The only difference with this MSSQL DB is that it uses BIGINT for its primary key and some of the column names are different (not that this matters).
What am I doing wrong?
UPDATE:
Whilte $stmt is not false, I looked at the error anyway, and it gives me
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -35
[code] => -35
[2] => Invalid type
[message] => Invalid type
The IMSSP leads me to believe that, according to documentation at http://php.net/manual/en/function.sqlsrv-errors.php, it's my SQL for PHP 2.0 driver that is causing the problem. I see that SQL for PHP 3.0 has been released. This could be the problem I suppose.. because the DB i'm trying to query is a newer version of MSSQL (2008? vs 2005) than the one I've been using previously without any problems. However, this driver has been compiled with VC9 only (2.0 was available for both), and my PHP 5.3 is compiled with VC6.. so it will not load. Does this mean I need to recompile it using the source code or re-install PHP with a VC9 version?
I don't know how to recompile, so I guess re-installing VC9 version of PHP 5.3 is the way to go for me right now.
@sign and see if you get an error$stmt === falsecheck for the error becausesqlsrv_query()isn't returning false. So, there is an error, but it' just wasn't being caught by the if-statement of thesqlsrv_error()block.