Php – Getting pdo_thesql driver to work in CLI

command-line-interfaceMySQLpdoPHP

I have a problem with the pdo_mysql extension in CLI. I'm working with a local LAMPP installation and making a info.php file I can see that I have PDO and the mysql driver enabled. But when I write php --ri mysql in the command line it returns Extension 'mysql' not present.
I've read both php.ini, the one for CLI and the one that loads for the browser and I can't see no differences in the pdo configuration. PDO is activated for CLI but pdo_mysql is not and I can't find any pdo_mysql.so file or any other file or line that tells me why is it working from the browser and not from the cli. Any help?

Thank you very much.

Best Answer

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 and 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