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

<?php
$serverName = "servername\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbname", "UID"=>"us", "PWD"=>"ps");
$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));
}
?>

can any one please help me to resolve this issue

Recommended Answers

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

Jump to Post

All 14 Replies

Re: connecting php thorugh MSSql 2008 80 80

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

Re: connecting php thorugh MSSql 2008 80 80

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

Re: connecting php thorugh MSSql 2008 80 80

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.

Re: connecting php thorugh MSSql 2008 80 80
<?php

$server = 'xyz\SQLEXPRESS';

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

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

just check it....

Re: connecting php thorugh MSSql 2008 80 80

Database connection error . kindly check the connection once again

Re: connecting php thorugh MSSql 2008 80 80

Hi anas.man

I am getting the same error

Re: connecting php thorugh MSSql 2008 80 80

Hi,

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

http://docs.gurock.com/testrail-admin/howto-installing-sqlsrv

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.

Regards,
Ben

commented: you hit it right on the head +8
Re: connecting php thorugh MSSql 2008 80 80

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

Re: connecting php thorugh MSSql 2008 80 80

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

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

Re: connecting php thorugh MSSql 2008 80 80

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

Re: connecting php thorugh MSSql 2008 80 80

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

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

Re: connecting php thorugh MSSql 2008 80 80

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

Re: connecting php thorugh MSSql 2008 80 80

Hi

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"
Re: connecting php thorugh MSSql 2008 80 80

thanks for support

i connect MSSQL thorugh ODBC.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.