Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function sqlsrv_connect() - Troubleshooting

System Information

CMS: Wordpress

Web Server: XAMPP

PHP Version: 5.5.30

MS Management Studio 17

Goal

Establish MSSQL Database connection using PHP

What has been done

  1. Downloaded SQLSRV Drivers
  2. Copied files php_pdo_sqlsrv_55_nts.dll and php_pdo_sqlsrv_55_ts.dll to the directory C:\xampp\php\ext
  3. Added the following lines to the dynamic extensions part in the php.ini file: extension=php_pdo_sqlsrv_55_ts.dll and extension=php_pdo_sqlsrv_55_nts.dll
  4. Restarted Web Server
  5. Confirmed sqlsrv is listed in phpinfo()

Code

$serverName = "technology-pc\sqlexpress";

// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"example_db");
$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));
}

Error

Call to undefined function sqlsrv_connect()

like image 499
Benjamin Löffel Avatar asked Sep 10 '25 19:09

Benjamin Löffel


1 Answers

You have added the PDO variant of SQLSRV drivers to the extension list, but have not added the base drivers php_sqlsrv_55_ts.dll.

Add to the php.ini:

extension=php_sqlsrv_55_ts.dll

or

extension=php_sqlsrv_55_nts.dll

Also, you really should be using either the Thread-Safe (_ts.dll) or Non-Thread-Safe (_nts.dll) versions of the driver, not both. I believe that, as you are using an Apache Server, you should be using the Thread-Safe versions. So you php.ini should have:

extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
like image 145
ImClarky Avatar answered Sep 13 '25 08:09

ImClarky