Kacper Turek
Kacper Turek

Reputation: 37

Uncaught Error: Call to undefined function sqlsrv_connect()

I installed xampp-win32-7.2.11-0-VC15-installer.exe, downloaded and extracted SQLSRV53.EXE to C:\xampp\php\ext, added

;extension=php_sqlsrv_72_ts_x64.dll

;extension=php_pdo_sqlsrv_72_ts_x64.dll

to php.ini and still get

Uncaught Error: Call to undefined function sqlsrv_connect()

my code:

<?php
        $serverName = "XXXXX\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"=>"XXXX");
        $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));
        }
    ?>

Upvotes: 0

Views: 3447

Answers (2)

Madhusudan
Madhusudan

Reputation: 407

  1. php_sqlsrv_72_ts_x64 AND php_pdo_sqlsrv_72_ts_x64 should be 32 bit same as xampp

  2. Also compatible with PHP version

Upvotes: 2

Shashank Shah
Shashank Shah

Reputation: 2167

In my case there were 2 php.ini files on wamp server. one of them is located at C:\wamp\bin\apache\Apachex.x.x\bin folder and when i tried to connect through sqlsrv_connect function, we are referring to the php.ini file in the apache folder.

So please check the php.ini in apache folder and enable the extension and test your connection with sqlsrv_connect.

Hope this will help.

Upvotes: 0

Related Questions