1. 程式人生 > >could not find driver 檢視PHPINFO PDO中PDO drivers no value

could not find driver 檢視PHPINFO PDO中PDO drivers no value

PDO drivers no value in Windows,有需要的朋友可以參考下。

 

學習php程式設計遇到

 

Uncaught exception 'PDOException' with message 'could not find driver'

 

或者

 

Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

 

整兩個問題,網上找了很多資料,很多是這樣解決的

 

配置php.ini檔案新增extension=php_pdo_mysql.dll,這樣就開啟pdomysql擴充套件庫

 

但是我沒有解決問題,問題還是老樣子,後來在stackoverflow 找到了問題所在

 

問題出在了

 

extension_dir = "ext"

 

改成絕對路徑就可以了

例如:

extension_dir = "D:/php-5.4.11-Win32-VC9-x86/ext"

 
; Directory in which the loadable extensions (modules) reside. ;http://php.net/extension-dir ; extension_dir = "./" ; On windows: extension_dir = "D:/php-5.4.11-Win32-VC9-x86/ext
原因
 

in php.ini andphp -mwas starting fine and reporting that it loaded pdo_mysql, but when I ran phpinfo.php through apache, the driver was missing.

I fixed it by changing theextension_dirto anabsolute path. I'm guessing it got confused when running through Apache and made it relative to something else.  

我固定它通過改變extension_dir絕對路徑。我猜它混淆了執行時通過Apache和相對於別的東西。