2017年2月18日 星期六

64位元的windows server下,PHP 的 ODBC 錯誤

作業系統都轉成64位元了,原本的WebServer也重架,一般架系統大概久久改版時才會更新一次,剛好趁這次的機會,把一些架系統可能會遇到的問題寫出來,免得以後還得重找。

於 windows平台,目前可以下載的PHP都是32位元的版本,在64位元的環境下,若使用[控制台]->[系統及安全性]->[系統管理工具] 下的ODBC設定,可能會出現下面的錯誤。

CC-dns 在 odbc_connect 有錯誤發生
PHP Warning: odbc_connect(): SQL error: [Microsoft][ODBC 驅動程式管理員] 指定之 DSN 中的驅動程式和應用程式架構不相符, SQL state IM014 in SQLConnect in C:\inetpub\wwwroot\includes\odbc_mssql.php on line 10 PHP Warning: odbc_close() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\includes\odbc_mssql.php on line 6 

這算是常見問題吧,請參見下面的說明。
You are attempting to use a 64 bit application with a 32 bit ODBC driver or vice versa. Look at ODBC on 64-bit Windows Platforms. You need to determine whether your PHP application is 64 bit or 32 bit first. Then once you've ascertained that you need to start the correct ODBC administrator - there are 2 of them, one for 32 bit and one for 64 bit. The 64 bit ODBC administrator is in Adminstrative tools, control panel and the 32 bit one is in %windir\syswow64\odbcad32.exe. Once you've matched your application architecture to the right ODBC administrator you need to create the system DSN. If you cannot find the MS Access driver in the administrator you'll need to download one for that architecture - I'm not sure if there is a 64 bit MS Access ODBC driver - if there isn't you'll have to change your application architecture. The article I reference has more information.

執行 %windir\syswow64\odbcad32.exe 來作設定,即可正常。
真實的目錄為 C:\Windows\SysWOW64\odbcad32.exe

參考文件:

64位元的windows server 2008下,PHP 的 ODBC 錯誤