Skip to content
Advertisement

Xampp php 5.6 mssql_connect() Fatal error: Call to undefined function mssql_connect() [closed]

I am using Xampp with PHP version 5.6. I was trying to connect using mssql_connect() function from the mssql PHP extension. But it shows me the error:

mssql_connect() Fatal error: Call to undefined function mssql_connect()

Can anybody help me for the same?

Thanks in advance

Advertisement

Answer

Explanations:

MSSQL extension (mssql_ functions) is not available anymore on Windows with PHP 5.3 or later.

Warning This feature was REMOVED in PHP 7.0.0.

Alternatives to this feature include: PDO_SQLSRV PDO_ODBC SQLSRV Unified ODBC API These functions allow you to access MS SQL Server database.

This extension is not available anymore on Windows with PHP 5.3 or later.

Solution:

What you can do is to install PHP Driver for SQL Server. You need to download the appropriate version of this driver. For PHP 5.6 – version 3.2 (32-bit or 64-bit also depends on PHP version). Also download and install an appropriate ODBC driver.

Sample script:

<?php
$serverName = "serverinstance,port";
$connectionInfo = array(
    "UID" => "username",
    "PWD" => "password",
    "Database" => "database"
);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
    echo "Unable to connect.</br>";
    exit;
} else {
    echo "Connected.</br>";
}

// Other code here ...

sqlsrv_close($conn);
?>
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement