1.11M Members

connecting php thorugh MSSql 2008

 
0
 

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

 
1
 

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

 
0
 

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

 
0
 

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.

 
0
 
<?php

$server = 'xyz\SQLEXPRESS';

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

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

just check it....

 
0
 

Database connection error . kindly check the connection once again

 
0
 

Hi anas.man

I am getting the same error

 
1
 

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

 
0
 

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

 
0
 

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

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

 
0
 

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

 
0
 

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

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

 
0
 

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

 
0
 

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"
 
0
 

thanks for support

i connect MSSQL thorugh ODBC.

Question Answered as of 6 Months Ago by matrixdevuk, pritaeas, BenWard and 2 others
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: