Fatal error: Uncaught Error: Call to function sqlsrv_connect() in C:\xampp\htdocs\DBtest\sqlsrv.php:7 Stack trace: #0 {main} SQLSERVER

Error problem:

Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\DBtest\sqlsrv.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\DBtest\sqlsrv.php on line 7

PHP for testing connection:

<?php
$serverName = "LAPTOP-NUUM4IGR\SQLEXPRESS"; //serverName\instanceName

// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"perkuliahan");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

PHP.ini file:

extension=php_pdo_sqlsrv_74_nts_x64.dll 
extension=php_pdo_sqlsrv_74_ts_x64.dll 
extension=php_sqlsrv_74_nts_x64.dll 
extension=php_pdo_sqlsrv_74_ts_x64.dll

pdo_sqlsrv on my phpinfo appears well. extension Ver 5.8.0 + 12928 I have installed ODBC PHP Version 7.4.10

Previously I used SQL SERVER 2008 R2, I guess that is not eligible so I upgraded to SQL Server 2012. But still stuck there was a mistake I did? I am very grateful for your solution.

Upvotes: 0

Views: 2734

Answers (1)

Hammad Ahmed khan
Hammad Ahmed khan

Reputation: 1671

The MSSQL extension is not available anymore on Windows with PHP 5.3 or later. SQLSRV, an alternative driver for MS SQL is available from Microsoft:

» http://www.microsoft.com/en-us/download/details.aspx?id=20098

1.Download SQLSRV32.EXE (Microsoft Drivers for PHP for SQL Server) from: http://www.microsoft.com/en-us/download/details.aspx?id=20098

2.Choose path: C:\xampp\php\ext

3.Uncomment or Append extension = php_sqlsrv_56_ts.dll in php.ini

4.Restart Apache from XAMPP Control Panel (Stop/Start)

I tested it and it works 100%

Upvotes: 0

Related Questions