SQLSRV is undefined only when one file calls it, works fine elsewhere
- SQLSRV is installed. I know it's installed because only one php file is giving this error. Every other file on the server is working fine, using the same commands.The set up:home.php uses sqlsrv to check the database for sections the user can access and display files in each section. That page works fine.When you click on one of the files, getfile.php, which is stored in the same folder as home.php, first connects to the database without issue, and then crashes on sqlsrv_fetch_array, with the above error message.The code originally, was:
$Query = "SELECT * FROM Sections WHERE ID='" . $_GET['s'] . "'"; $Section = sqlsrv_fetch_array(sqlsrv_query($DB, $Query));
home.php runs a while on the array fetching, so on it, the code is:$Query = "SELECT * FROM Sections"; $Sections = sqlsrv_query($DB, $Query); $JID = 1; while ($Section = sqlsrv_fetch_array($Sections)){So I tried changing the code on getfile.php to:$Query = "SELECT * FROM Sections WHERE ID='" . $_GET['s'] . "'"; $Temp = sqlsrv_query($DB, $Query); $Section = sqlsrv_fetch_array($Temp);
And that still errors out:Fatal error: Call to undefined function sqlsrv_query() in [Path]\getfile.php on line 31Keep in mind, before telling me sqlsrv is undefined, it uses it to connect to the database without any problems, and uses the exact same code in a file in the same folder without any problems.
I've tried restarting IIS with no luck.
Answers
The fatal error is reported by the PHP run-time and not by the driver. It actually means that PHP was unable to locate and/or load the driver. One easy way to verify that the driver is operational is to retrieve a configuration parameter (no database connection being needed). For instance:
$mode = sqlsrv_get_config('WarningsReturnAsErrors');
If calling “sqlsrv_get_config” does not trigger a fatal error, then “sqlsrv_query” should not as well.
Thank you,
Serban
Serban Iliescu - MSFT- Proposed As Answer byCharles Wang - MSFTMSFT, ModeratorTuesday, October 20, 2009 12:13 PM
- Marked As Answer byCharles Wang - MSFTMSFT, ModeratorThursday, October 22, 2009 2:00 PM
All Replies
The fatal error is reported by the PHP run-time and not by the driver. It actually means that PHP was unable to locate and/or load the driver. One easy way to verify that the driver is operational is to retrieve a configuration parameter (no database connection being needed). For instance:
$mode = sqlsrv_get_config('WarningsReturnAsErrors');
If calling “sqlsrv_get_config” does not trigger a fatal error, then “sqlsrv_query” should not as well.
Thank you,
Serban
Serban Iliescu - MSFT- Proposed As Answer byCharles Wang - MSFTMSFT, ModeratorTuesday, October 20, 2009 12:13 PM
- Marked As Answer byCharles Wang - MSFTMSFT, ModeratorThursday, October 22, 2009 2:00 PM


