PHP 7 x64 ODBC错误连接到MSSQL数据库

Getting the following error when testing an upgrade to PHP7 x64:

odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I've installed the following:

  • PHP 7.0.0 x64
  • Microsoft ODBC Driver 11 for SQL Server x64
  • Microsoft Visual C++ 2015 Redistributable x64
  • Microsoft Visual C++ 2015 Redistributable x86
  • The (thread-safe) preview of the PHP 7 MSSQL drivers: https://github.com/Azure/msphpsql

I have uncommented/added the following lines of my phpini:

  • extension=php_pdo_mysql.dll (uncommented)
  • extension=php_odbc.dll (added)
  • extension=php_sqlsrv_7_ts.dll (added)
  • extension=php_pdo_sqlsrv_7_ts.dll (added)

Things to consider:

  • I can see that the modules are indeed loaded in phpinfo.
  • I've added the ODBC connection and can see it in System DSN.
  • I am successfully able to connect via sqlsrv_connect() but not odbc_connect(), which is what all our previous PHP 5.6 scripts are using.

Can't seem to find the answer anywhere else. Any help would be appreciated. Thanks.

I seem to have solved my own issue.

Turns out, the ODBC_CONNECT string uses an explicit DSN name and not a database, apparently...

Previously my ODBC Connect string was $conn = odbc_connect('DB',$DBUSER, $DBPASS) and my ODBC Data Source was "SERVERNAME"

Once I changed the ODBC Data Source name to match the DB name, it worked.