Hi Friend

I am trying to connect my MSSql server 2008 R2 server using php. I am getting an error as below

Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\test\connect.php on line 4

and the code is below

$serverName = "servername\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbname", "UID"=>"us", "PWD"=>"ps");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

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

can any one please help me to resolve this issue

Check your PHP.INI to see if the SQL Server extension is enabled.

I think you need mssql_connect() or mssql_pconnect() dont you?

Hi Pritaeas

I have enabled the sql extension. But it is not showing in php.ini file.

can you pls help me. how to cross verify the extension enable.


$server = 'xyz\SQLEXPRESS';

$link = mssql_connect($server, 'ab', 'abc');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');

just check it....

Database connection error . kindly check the connection once again

Hi anas.man

I am getting the same error


You need to check your php.ini. It looks as though your php has not loaded the sqlsrv extension.


be aware that there are 2 sql server drivers;

  1. mssql (old & community supported, but available on linux)
  2. sqlsrv (new and microsoft supported, NOT available on linux)

the drivers for these are php_mssql.dll and php_sqlsrv.dll respectively.

It would seem likely to me that you either haven't enabled either driver in your php.ini OR you have enabled the mssql driver instead of the sqlsrv one.

note: just typing extension=php_sqlsrv.dll into your ini wont help if the binary dll file isn't there on your machine.


commented: you hit it right on the head +8

Give it a shot by using PDO. I think this will work.

Give it a shot by using PDO. I think this will work.

Even with PDO, you still need the right extensions working first.

If they have control over the server, one of these should work:
sudo apt-get install php-mysql
yum install php-mysql

If they have control over the server, one of these should work:

If you look closely at the OP, this is about SQL Server.

Haha, derp.
I forgot they used Win. Server. xDDD


I have install MSSQL drivers.But still i am unable to get MSSQL information in phpinfo file.

But i am getting as below

Configure Command 

cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" "--with-pgo"

thanks for support

i connect MSSQL thorugh ODBC.