1,105,288 Community Members

connecting php thorugh MSSql 2008

Member Avatar
rpv_sen
Posting Whiz in Training
260 posts since Mar 2011
Reputation Points: 14 [?]
Q&As Helped to Solve: 21 [?]
Skill Endorsements: 1 [?]
 
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

Member Avatar
pritaeas
mod_pritaeas
11,313 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
1
 

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

Member Avatar
BenWard
Newbie Poster
15 posts since Jan 2011
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
rpv_sen
Posting Whiz in Training
260 posts since Mar 2011
Reputation Points: 14 [?]
Q&As Helped to Solve: 21 [?]
Skill Endorsements: 1 [?]
 
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.

Member Avatar
anas.man
Newbie Poster
18 posts since Dec 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 
<?php

$server = 'xyz\SQLEXPRESS';

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

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

just check it....

Member Avatar
baig123
Newbie Poster
12 posts since Dec 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Database connection error . kindly check the connection once again

Member Avatar
rpv_sen
Posting Whiz in Training
260 posts since Mar 2011
Reputation Points: 14 [?]
Q&As Helped to Solve: 21 [?]
Skill Endorsements: 1 [?]
 
0
 

Hi anas.man

I am getting the same error

Member Avatar
BenWard
Newbie Poster
15 posts since Jan 2011
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
matrixdevuk
Light Poster
41 posts since Jan 2014
Reputation Points: 13 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
pritaeas
mod_pritaeas
11,313 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

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

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

Member Avatar
matrixdevuk
Light Poster
41 posts since Jan 2014
Reputation Points: 13 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
pritaeas
mod_pritaeas
11,313 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
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.

Member Avatar
matrixdevuk
Light Poster
41 posts since Jan 2014
Reputation Points: 13 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
rpv_sen
Posting Whiz in Training
260 posts since Mar 2011
Reputation Points: 14 [?]
Q&As Helped to Solve: 21 [?]
Skill Endorsements: 1 [?]
 
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"
Member Avatar
rpv_sen
Posting Whiz in Training
260 posts since Mar 2011
Reputation Points: 14 [?]
Q&As Helped to Solve: 21 [?]
Skill Endorsements: 1 [?]
 
0
 

thanks for support

i connect MSSQL thorugh ODBC.

Question Answered as of 2 Months Ago by matrixdevuk, pritaeas, BenWard and 2 others
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: