简体   繁体   English

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

[英]PHP 7 x64 ODBC Error Connecting to MSSQL Database

Getting the following error when testing an upgrade to PHP7 x64: 测试升级到PHP7 x64时出现以下错误:

odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified odbc_connect():SQL错误:[Microsoft] [ODBC驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序

I've installed the following: 我安装了以下内容:

  • PHP 7.0.0 x64 PHP 7.0.0 x64
  • Microsoft ODBC Driver 11 for SQL Server x64 用于SQL Server x64的Microsoft ODBC驱动程序11
  • Microsoft Visual C++ 2015 Redistributable x64 Microsoft Visual C ++ 2015 Redistributable x64
  • Microsoft Visual C++ 2015 Redistributable x86 Microsoft Visual C ++ 2015 Redistributable x86
  • The (thread-safe) preview of the PHP 7 MSSQL drivers: https://github.com/Azure/msphpsql PHP 7 MSSQL驱动程序的(线程安全)预览: https//github.com/Azure/msphpsql

I have uncommented/added the following lines of my phpini: 我已经取消注释/添加了以下我的phpini行:

  • extension=php_pdo_mysql.dll (uncommented) extension = php_pdo_mysql.dll(取消注释)
  • extension=php_odbc.dll (added) extension = php_odbc.dll(已添加)
  • extension=php_sqlsrv_7_ts.dll (added) extension = php_sqlsrv_7_ts.dll(已添加)
  • extension=php_pdo_sqlsrv_7_ts.dll (added) extension = php_pdo_sqlsrv_7_ts.dll(已添加)

Things to consider: 需要考虑的事项:

  • I can see that the modules are indeed loaded in phpinfo. 我可以看到模块确实是在phpinfo中加载的。
  • I've added the ODBC connection and can see it in System DSN. 我添加了ODBC连接,可以在系统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. 我成功地通过sqlsrv_connect()而不是odbc_connect()连接,这是我们以前的所有PHP 5.6脚本都使用的。

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... 事实证明,ODBC_CONNECT字符串使用显式DSN名称而不是数据库,显然......

Previously my ODBC Connect string was $conn = odbc_connect('DB',$DBUSER, $DBPASS) and my ODBC Data Source was "SERVERNAME" 以前我的ODBC Connect字符串是$ conn = odbc_connect('DB',$ DBUSER,$ DBPASS),我的ODBC数据源是“SERVERNAME”

Once I changed the ODBC Data Source name to match the DB name, it worked. 一旦我更改了ODBC数据源名称以匹配数据库名称,它就可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM