Reputation: 839
It's my first time integrating php with SQL Server. The SQL server in context is located on another physical computer on the same LAN. I'm using the configuration explained below:
I'm being faced with the error below:
Connection could not be established.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) ).
The code being used follows below:
<?php
$serverName = "TESTSERV\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbname", "UID"=>"username", "PWD"=>"password");
$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 anyone guide me on what needs to be done here in order to successfully connect to the database?
Upvotes: 2
Views: 897
Reputation: 4310
Microsoft SQL Server Driver for PHP requires installation of Microsoft SQL Server 2012 Native Client as you can read in error message. Only downloading of extension dll is not enough. You can read more in official System Requirements (Microsoft Drivers for PHP for SQL Server).
Versions 3.2 and 3.1 require Microsoft ODBC Driver 11 (or higher) for SQL Server. To download the Microsoft ODBC Driver 11 for PHP for SQL Server, see Microsoft ODBC Driver 11 for SQL Server.
If you are using the SQLSRV driver, sqlsrv_client_info will return information about which version of SQL Server Native Client is being used by the Microsoft Drivers for PHP for SQL Server. If you are using the PDO_SQLSRV driver, you can use PDO::getAttribute to discover the version.
https://www.microsoft.com/en-us/download/details.aspx?id=36434
Download, install and try to refresh your testing page.
Upvotes: 2