Home >Backend Development >PHP Tutorial >Why am I getting a 'Call to undefined function mssql_connect()' error when connecting to SQL Server from PHP?

Why am I getting a 'Call to undefined function mssql_connect()' error when connecting to SQL Server from PHP?

DDD
DDDOriginal
2024-11-10 03:49:031007browse

Why am I getting a

PHP Fatal Error: Call to Undefined Function mssql_connect()

Issue:
When attempting to connect to SQL Server 2008 from PHP 5.3 running on IIS7/Windows Server 2008, users receive the fatal error "Call to undefined function mssql_connect()."

Resolution:

To resolve this issue, ensure the following:

Proper Extension Configuration:

  • Verify that SQLSRV30.EXE is installed in the correct directory (C:Program Files (x86)PHPext) and that the .dll file extension matches the version of PHP (php_sqlsrv_53_nts.dll for PHP 5.3).
  • Add the following line to C:Program Files (x86)PHPphp.ini:

    extension=php_sqlsrv_53_nts.dll
  • Restart the server to apply the changes.

PHPINFO Verification:

  • Access phpinfo() to check if the SQLSRV extension is loaded. Look for a section similar to the following:

    SQLSRV
    SQLSRV support => enabled
    SQLSRV Info => 
    SQLSRV Session State => enabled
    SQLSRV Client Adapter => yes

Correct Function Usage:

  • Remember that mssql_connect() is for the Mssql extension, not the Microsoft SQL Server extension (sqlsrv).
  • For the Microsoft driver API, use sqlsrv_connect(). Reference SQLSRV_Help.chm in the ext directory for more information.

Extension Directory:

  • Check the extension_dir setting in php.ini. If it is not set to "ext," try specifying the full path to the directory:

    extension_dir = "C:PHPext"
  • Restart the server after making any changes to the php.ini file.

The above is the detailed content of Why am I getting a 'Call to undefined function mssql_connect()' error when connecting to SQL Server from 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