PHP Fatal error: Call to undefined function mssql_connect()

PHP Fatal error: Call to undefined function mssql_connect()

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

PHP Fatal error: Call to undefined function mssql_connect()

You are encountering a classic architectural mismatch between the legacy Microsoft Database extension and modern SQL Server driver requirements. The mssql_* functions, such as mssql_connect(), were part of the original MSSQL extension bundled with older PHP distributions. These functions rely on the FreeTDS library or an internal Microsoft client that is no longer supported in current PHP environments.

In your specific environment—PHP 5.3 running on Windows Server 2008 R2 with IIS7—the error occurs because you are attempting to use a function that was explicitly disabled during the compilation of your PHP binary. Your phpinfo output confirms this under the Configure Command line: --without-mssql and --without-pdo-mssql.

You have correctly downloaded SQLSRV30.EXE (the official Microsoft ODBC Driver for SQL Server) and enabled the corresponding DLL (php_sqlsrv_53_nts.dll) in your php.ini. This is the correct path forward, but you are still seeing errors because the code attempting to connect is looking for the old, non-existent functions.

To resolve this, you must switch your application logic to use the new SQL Server Native Driver API provided by the extension you just installed. The function names have changed significantly:

  • Old (Legacy): mssql_connect(), mssql_query(), mssql_close()
  • New (Native Driver): sqlsrv_connect(), sqlsrv_query(), sqlsrv_free_stmt()

Here is how you should refactor your connection logic. Instead of calling mssql_connect('server', 'username', 'password'), use the following pattern:

<?php
$connectionInfo = array(
    "Database" => "AdventureWorks",
    "UID" => "your_username",
    "PWD" => "your_password",
    "CharacterSet" => "UTF-8"
);

$conn = sqlsrv_connect("localhost", $connectionInfo);

if ($conn === false) {
    $errors = sqlsrv_errors();
    // Handle errors appropriately
}

$stmt = sqlsrv_query($conn, "SELECT TOP 10 * FROM Employees");
while (($row = sqlsrv_fetch_array($stmt)) !== false) {
    echo $row['FirstName'];
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>

One critical detail to verify in your setup is the Server API configuration. Your phpinfo indicates you are running PHP in CGI/FastCGI mode (Server API: CGI/FastCGI). When using IIS7, this is often handled via FastCGI or a configured Application Pool. Ensure that the path to php.ini specified by IIS matches the one where you added the extension line. You listed C:\Program Files (x86)\PHP\php.ini, but your configuration file path shows C:\Windows. If IIS is loading PHP from a different directory than the one containing your .dll, the extension will not load, and even if you fix the function calls, you might hit other undefined function errors later.

Additionally, be aware of version compatibility. You are using SQL Server 2008 with PHP 5.3. While the php_sqlsrv driver supports this combination, Microsoft eventually deprecated support for older SQL versions in favor of newer drivers that require PHP 7 or higher. If you can upgrade your PHP version to 7.4 or later (which is supported on Windows Server 2012 and above), you gain access to the pdo_sqlsrv driver as well.

The PDO approach offers a more uniform API across different database engines:

$dsn = "sqlsrv:Server=localhost;Database=AdventureWorks";
$options = [
    SQLSRV_ATTR_ENCODING => SQLSRV_ENC_UTF_8,
];

$conn = new PDO($dsn, 'your_username', 'your_password', $options);
$stmt = $conn->prepare("SELECT TOP 10 * FROM Employees");
$stmt->execute();

However, sticking with the sqlsrv_* functions is perfectly valid for legacy PHP 5.3 environments and avoids the overhead of re-architecting existing codebases immediately. Just ensure you stop calling any mssql_ functions, as they will never exist in a build configured without them.

Our network