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?

Rick Roy
  • 1,656
  • 2
  • 21
  • 47
  • 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: http://stackoverflow.com/questions/24776078/cannot-call-function-sqlsrv-connect – Havenard Jun 18 '15 at 06:02
  • @Havenard I have followed the manual given here http://php.net/manual/en/function.sqlsrv-connect.php – Rick Roy Jun 18 '15 at 06:05

1 Answers1

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)

Protomen
  • 9,471
  • 9
  • 57
  • 124
  • 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 – Rick Roy Jun 18 '15 at 06:03
  • There is no such lines in my php.ini is it ok if I go ahead and add those lines by myself? – Rick Roy Jun 18 '15 at 06:13