Getting pdo_mysql driver to work in CLI
I have a problem with the pdo_my开发者_开发问答sql 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.
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
Problem solved. I have two php installations, one installed by LAMPP that has all the required pdo drivers and one installed in the system (I don't know if it comes with ubuntu by default or I installed it at some point) with PDO enabled but no PDO drivers. CLI works with the second PHP unless you tell him otherwise. I was working with Doctrine from the CLI but I was executing a bash file that calls some php code. In the first line of the .doctrine file I can tell the system what php I want to use:
#!/root/to/lampp/php
And it worked (actually it doesn't create the database tables that it's supposed to create but that's a different problem thet I still have to solve.
精彩评论