php 7.0 sqlsrv_connect to SQL 2008 R2

Category: sql server driverphp

Question

firstnamelast on Mon, 05 Mar 2018 14:01:39


Hi,

Could someone help us resolve the issue, thank in advance? We are using php 7, sql server 2008 r2 on windows server 2008 r2 sp1, iis 7.5.

The issue is we are upgrading code to work with php 7, earlier there was mssql_connect and mssql_* functions that were working so far but not anymore on php 7. So we are now trying to make similar function sqlsrv_connect and sqlsrv_* to work, it does not work at the moment we are stuck with this error dump. Please notice that we have already installed the Microsoft ODBC Driver as mentioned in the error message but still we receive the same error.

Here is testcode:

$serverName = "serverName"; 
$dbusername = "dbusername";
$dbpassword = "dbpassword";
$dbname = 'dbname';

$connectionInfo = array( "Database"=>$dbname, "UID"=>$dbusername, "PWD"=>$dbpassword);

$link = sqlsrv_connect( $serverName, $connectionInfo);

if( $link !== false ) {
	echo "Connection established.".PHP_EOL;
}
else{
	die( print_r( sqlsrv_errors(), true));
}




Here is error message:

Array(
	[0] => Array
		(
			[0] => IMSSP
			[SQLSTATE] => IMSSP
			[1] => -49
			[code] => -49
			[2] => This extension requires the Microsoft ODBC Driver 11 or 13 for SQL Server. Access the following URL to download the ODBC Driver 11 or 13 for SQL Server for x64: http://go.microsoft.com/fwlink/?LinkId=163712
			[message] => This extension requires the Microsoft ODBC Driver 11 or 13 for SQL Server. Access the following URL to download the ODBC Driver 11 or 13 for SQL Server for x64: 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
		)
)


Here is screenshot of odbc datasource:
https://i.stack.imgur.com/PoQAK.png


Here are screenshots of php config
sqlsrv config

https://i.stack.imgur.com/4BEpm.png

odbc conf

https://i.stack.imgur.com/zsShM.png

pdo

https://i.stack.imgur.com/f1P9r.png

One more thing, if we need to install odbc drivers anyways why should one bother with Microsoft drivers. Is there anythnig I am missing?

Replies

firstnamelast on Mon, 05 Mar 2018 14:26:29


hello everybody,

I was not allowed to upload screen shots nor links because I need to verify my email, but I do not see anywhere, how do I verify my account/email.

I have posted the same question here

https://stackoverflow.com/questions/49112605/php-7-sqlsrv-connect-issue

please help me.

Olaf Helper on Mon, 05 Mar 2018 14:52:03


This extension requires the Microsoft ODBC Driver 11 or 13 for SQL Server.

You have to install that ODBC Provider: Microsoft® ODBC Driver 13.1 for SQL Server® - Windows, Linux, & macOS

firstnamelast on Tue, 06 Mar 2018 06:48:20


Yes we have it installed. Please see the screenshot here https://i.stack.imgur.com/PoQAK.png