简体   繁体   English

让pdo_mysql驱动程序在CLI中工作

[英]Getting pdo_mysql driver to work in CLI

I have a problem with the pdo_mysql extension in CLI. 我在CLI中的pdo_mysql扩展有问题。 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. 我正在使用本地LAMPP安装并制作一个info.php文件我可以看到我已经启用了PDO和mysql驱动程序。 But when I write php --ri mysql in the command line it returns Extension 'mysql' not present . 但是当我在命令行中编写php --ri mysql ,它返回扩展'mysql'不存在 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. 我已经阅读了php.ini,一个用于CLI,另一个用于浏览器,我看不到pdo配置的差异。 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. PDO被激活用于CLI,但是pdo_mysql没有激活,我找不到任何pdo_mysql.so文件或任何其他文件或行,告诉我它为什么在浏览器而不是从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 . 我正在使用ubuntu + mysql(个人安装非灯)和php cli通过apt sudo apt-get install php5-cli PDO is installed by default but the appropriate db driver (mysql in my case) wasn't installed. PDO默认安装,但没有安装相应的db驱动程序(在我的情况下为mysql)。 This can be verified from the command line php --ri pdo which results in PDO support=>enabled and PDO drivers=>(blank) 这可以从命令行php --ri pdo验证,这导致PDO支持=>启用,PDO驱动程序=>(空白)

to rectify this for mysql install the php5-mysql module via sudo apt-get install php5-mysql . 通过sudo apt-get install php5-mysql来修复这个for mysql安装php5-mysql模块。 Obviously, do this after you've installed php5-cli. 显然,在安装php5-cli后执行此操作。 If you're using another db (eg postgres or odbc) look for the appropriate module name via sudo apt-cache search php5 如果您正在使用另一个数据库(例如postgres或odbc),请通过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. 我有两个php安装,一个由LAMPP安装,具有所有必需的pdo驱动程序和一个安装在系统中(我不知道它是默认配备ubuntu还是我在某些时候安装它)启用了PDO但没有PDO驱动程序。 CLI works with the second PHP unless you tell him otherwise. CLI使用第二个PHP,除非你告诉他。 I was working with Doctrine from the CLI but I was executing a bash file that calls some php code. 我正在使用CLI中的Doctrine,但我正在执行一个调用一些php代码的bash文件。 In the first line of the .doctrine file I can tell the system what php I want to use: 在.doctrine文件的第一行,我可以告诉系统我想要使用什么PHP:

#!/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. 它工作(实际上它不会创建它应该创建的数据库表,但这是一个不同的问题,我仍然需要解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM