Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

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

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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%WindowsSysWoW64 folder.

The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%WindowsSystem32 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...