Fatal error: Call to undefined function sqlsrv_connect()

Fatal error: Call to undefined function sqlsrv_connect()

There are mostly two php.ini changes files located, in my case, for wamp or xampp server.
One is simple change under the php custom folder changes and the other changes one is in the path of C:\wamp\bin\apache\Apachex.x.x\bin folder.
When connecting to SQL database through sqlsrv_connect used this function,
we are referring to simple the php.ini file in the apache folder.

Add the following php latest version (as per your version) to this file:


PHP Config File Check

Use this simple script to check the your php version:

Step by Step (call to undefined function sqlsrv_connect() xampp)

Step 1

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

Step 2

Choose path: C:\xampp\php\ext

Step 3

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

Step 4

Last step to Restart Apache from XAMPP or wamp server Control Panel (Stop/Start)

Load the simple PHP drivers in php.ini file and restart the server.


SQL Connection Simple way

"pakainfo", "UID"=>"sa", "PWD"=>"pakainfo@123");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

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



SQL Query

$query="select * from pakainfo where mst_id=1";
$stmt = sqlsrv_query( $conn, $query );
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {

Best Solutions

The error message “Call to undefined function sqlsrv_connect()” usually occurs when you are trying to connect to a Microsoft SQL Server database using PHP and the necessary PHP SQL Server extension is not enabled or installed on your server.

To fix this error, you need to ensure that the PHP SQL Server extension is enabled and properly configured on your server. Here are some steps you can follow:

Check if the SQL Server extension is installed by creating a PHP file with the following code:

Open this file in your web browser and search for “sqlsrv” or “pdo_sqlsrv” under the “Registered PHP Streams” section. If the extension is not listed, you need to install it.

Install the PHP SQL Server extension. You can install it using a package manager or by manually downloading and installing the extension. You can find the installation instructions and the download link on the Microsoft website.

Once the extension is installed, enable it in your PHP configuration file (php.ini). Add the following line to your php.ini file:


Finally, restart your web server to apply the changes.

After completing these steps, the “Call to undefined function sqlsrv_connect()” error should be resolved, and you should be able to connect to your Microsoft SQL Server database using PHP.


Leave a Comment