Home  >  Article  >  Backend Development  >  How to Fix the "Fatal Error: Call to Undefined Function sqlsrv_connect()" in PHP?

How to Fix the "Fatal Error: Call to Undefined Function sqlsrv_connect()" in PHP?

Barbara Streisand
Barbara StreisandOriginal
2024-11-12 22:38:02498browse

How to Fix the

Diagnosing the "Fatal Error: Call to Undefined Function sqlsrv_connect()"

The "Fatal error: Call to undefined function sqlsrv_connect()" error message indicates that you are attempting to use the sqlsrv functions without properly configuring your PHP environment.

To resolve this issue, ensure that you have installed the correct version of the PHP SQL Server driver that matches your PHP version, architecture, and compiler settings. Here is a checklist to follow:

  1. Verify PHP Version: Ensure that the version of PHP loaded by your web server matches the version of SQLSRV being installed. (Run PHPinfo() to confirm.)
  2. Check Architecture: Validate that the architecture of the driver (32/64 bit) corresponds to your server's architecture.
  3. Confirm Compiler: Verify that the driver was compiled with the same compiler as your PHP build (VC9, VC10, etc.).
  4. Restart Apache: After installing the driver, restart your web server to register the new extension.
  5. Configure php.ini: Add the extension directive to your php.ini file to load the driver. (Example: extension=c:/wamp/bin/php/php5.4.16/ext/php_sqlsrv_53_ts.dll)
  6. Check Startup Errors: Use the following command to verify that there are no startup errors:
php -d display_startup_errors=1 -d error_reporting=-1 -d display_errors -c "C:\Path\To\php.ini" -m

Once you have carefully checked each step, you should be able to connect to SQL Server via PHP using the sqlsrv functions. You will need to ensure that your connection string has the correct parameters for your database server (e.g., server name, username, password, database name).

The above is the detailed content of How to Fix the "Fatal Error: Call to Undefined Function sqlsrv_connect()" in PHP?. 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