PDO_ODBC: Data source name not found and no default driver specified

随声附和 提交于 2019-11-28 10:12:53

问题


I'm trying to access an ODBC connection in PHP via PDO_ODBC. This is my code:

$db = new PDO('odbc:MyDSN', '', '');

And I'm getting this error:

SQLSTATE[IM002] SQLConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I know the DSN is working because I can use it in Python with pyodbc. The type is User DSN - does it need to be a System DSN? I'm not specifying a driver because I figured ODBC was abstracting that away, but maybe I need to? The underlying DB is Oracle, if that helps.

Thank you!


回答1:


There are actually two separate Microsoft ODBC Administrator apps, one for 32-bit and one for 64.

As this KB article explains:

The 32-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\SysWoW64 folder.

The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\System32 folder.

Nope, not a typo -- the 32-bit version is in the SysWoW64 folder and the 64-bit is in the System32 folder. (o_O)

I was running a 64-bit web server which was checking the 64-bit ODBC library for the DSN, whereas I had it in the 32-bit. Downgrading the server did the trick.



来源:https://stackoverflow.com/questions/17841948/pdo-odbc-data-source-name-not-found-and-no-default-driver-specified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!