How to enable PDO_MYSQL for CLI?

梦想的初衷 提交于 2019-12-04 20:13:48
gofaster

I'm using ubuntu+mysql (individual install non-lamp) and php cli via apt:

sudo apt-get install php5-cli

PDO is installed by default but the appropriate db driver (mysql in my case) wasn't installed. This can be verified from the command line php --ri pdo which results in:

PDO support => enabled
PDO drivers => [ blank ]

To rectify this for mysql, install the php5-mysql module via

sudo apt-get install php5-mysql

Obviously, do this after you've installed php5-cli. If you're using another db (e.g. postgres or odbc) look for the appropriate module name via

sudo apt-cache search php5

Sorry, crossposted from my answer here.

check the php.ini in your apache folder and copy the PDO information to the php.ini in your php folder.

In my lampp configuration I just have 'extension=pdo.so' in php.ini

I think these answers are a bit old. Correct answer would be sudo apt-get install php-mysql. Executing php5-mysql would result in no package found, specially on machines which has php7-cli installed. As mentioned problem is that though PDO support is enabled, no driver installed. I simply resolved it by executing the above command.

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