0

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

Zhorov
  • 28,486
  • 6
  • 27
  • 52
  • Possible duplicate of [PHP Fatal error: Call to undefined function mssql\_connect()](https://stackoverflow.com/questions/9986804/php-fatal-error-call-to-undefined-function-mssql-connect) – zero3nna Aug 07 '19 at 10:21
  • 1
    You need to use `sqlsrv_connect()`. – N'Bayramberdiyev Aug 07 '19 at 10:33
  • 1
    **Danger**: PHP 5.6 is beyond end of life and is **unsupported**. Upgrade to a current version of PHP. – Quentin Aug 07 '19 at 10:36

1 Answers1

0

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 = "server\instance,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);
?>
Zhorov
  • 28,486
  • 6
  • 27
  • 52