Reputation: 1728
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?
Upvotes: 1
Views: 1948
Reputation: 9714
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
Select download by your PHP version:
SQLSRV30.EXE
if use SQL Server 2005
SQLSRV31.EXE
or SQLSRV31.EXE
if use SQL Server 2008
php_sqlsrv_55_ts.dll
fot ext
folderFor 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)
Upvotes: 2