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

6
Contributors
14
Replies
53
Views
3 Years
Discussion Span
Last Post by rpv_sen
Featured Replies
  • 1

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

  • 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 … Read More

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....

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

Comments
you hit it right on the head
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

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"

Edited by rpv_sen

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.