1

I am trying to connect to a mssql server using php. The sql server is on a different machine in the network and I have XAMPP installed in my machine. I don't have microsoft sql installed in my server.

I have downloaded the sqlsrv drivers for PHP and then in my php.ini file added the extension extension=php_pdo_sqlsrv_55_ts.dll under windows extension.

Added the php_pdo_sqlsrv_55_ts.dll file inside the php\ext\ folder of my XAMPP installation.

After restarting apache phpinfo(); shows that the sqlsrv driver is enabled

PDO support enabled
PDO drivers mysql, sqlite, sqlsrv

This is my code

<?php
$serverName = "192.168.100.102, 1433";
$connectionInfo = array( "Database"=>"ATP", "UID"=>"raihan", "PWD"=>"temp123#");
$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));
}
?>

But on executing I get this error

Fatal error: Call to undefined function sqlsrv_connect() in D:\xampp\htdocs\database\index.php on line 4

Why this error? And how do I go about connecting to mssql server using php?

2
  • php_pdo_sqlsrv_55_ts.dll this looks like an extension to PDO, not a set of standalone functions. I believe the extension you must load is php_sqlsrv_55_ts.dll, following the example of this similar quesiton: stackoverflow.com/questions/24776078/… Commented Jun 18, 2015 at 6:02
  • @Havenard I have followed the manual given here php.net/manual/en/function.sqlsrv-connect.php Commented Jun 18, 2015 at 6:05

1 Answer 1

2

php\etc\ sounds like wrong folder, try put in php\ext\ folder

Note extension=php_pdo_sqlsrv_55_ts.dll is used by PDO class

  1. Go to https://www.microsoft.com/en-us/download/details.aspx?id=20098
  2. Select download by your PHP version:

    • Select SQLSRV30.EXE if use SQL Server 2005
    • Select SQLSRV31.EXE or SQLSRV31.EXE if use SQL Server 2008
  3. After download, extract dlls
  4. If you use php with ThreadSafe (apache2handler -- more probable) copy php_sqlsrv_55_ts.dll fot ext folder

For use sqlsrv uncomment (or put) this line in php.ini extension=php_sqlsrv_55_ts.dll (or extension=php_sqlsrv_55_nts.dll for no-thread-safe)

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry that was a typo it has been saved inside the ext folder and I have also uncommented the extension=php_pgsql.dll but I still get the same error
There is no such lines in my php.ini is it ok if I go ahead and add those lines by myself?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.