Home >Backend Development >PHP Tutorial >Why Am I Getting a 'Fatal Error: Call to Undefined Function sqlsrv_connect()'?

Why Am I Getting a 'Fatal Error: Call to Undefined Function sqlsrv_connect()'?

Susan Sarandon
Susan SarandonOriginal
2024-11-25 09:26:11212browse

Why Am I Getting a

Troubleshooting "Fatal Error: Call to Undefined Function sqlsrv_connect()"

The "Fatal error: Call to undefined function sqlsrv_connect()" indicates that the PHP script is attempting to use the sqlsrv_connect() function, which is not available in the current PHP environment.

To resolve this issue, it's essential to verify that the php_sqlsrv_54_ts.dll extension is properly installed and loaded. Ensure that the following steps are followed:

  1. Check PHP Version and Architecture: Confirm that the installed SQLSRV extension matches the PHP version and architecture (32/64 bits) running on your system.
  2. Correct php.ini Location: Use the correct php.ini file as displayed in the phpinfo() output. Typically, WAMP installs PHP in multiple locations; make sure to edit the php.ini located in the active PHP folder.
  3. Restart Apache: After making changes to the php.ini file, restart the Apache service to load the updated configuration.
  4. Check Startup Errors: Use the command line to check for any startup errors or warnings:
php -d display_startup_errors=1 -d error_reporting=-1 -d display_errors -c "C:\Path\To\php.ini" -m

This command should display the sqlsrv module in the output if properly loaded.

  1. Check phpinfo() Output: Verify that the sqlsrv extension is listed in the phpinfo() output. This will confirm if the extension is successfully loaded into the PHP environment.

By following these steps, you can resolve the "Fatal Error: Call to undefined function sqlsrv_connect()" issue and connect to Microsoft SQL Server from your PHP script.

The above is the detailed content of Why Am I Getting a 'Fatal Error: Call to Undefined Function sqlsrv_connect()'?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn