简体   繁体   English

如何为CLI启用PDO_MYSQL?

[英]How to enable PDO_MYSQL for CLI?

I'm trying to learn the Symfony framework for PHP but having issues with the command line version of php. 我正在尝试学习PHP的Symfony框架,但遇到php命令行版本的问题。

When trying to create the database tables: 尝试创建数据库表时:

./symfony doctrine:insert-sql

I'm getting the following error: 我收到以下错误:

Couldn't locate driver named mysql

This is only an issue with the command line version of php. 这只是php的命令行版本的一个问题。 I've had doctrine working no problem. 我的学说没有问题。

After quickly reading up on the problem, it seems I need to enable PDO_MYSQL for the CLI installation of php. 在快速阅读问题后,似乎我需要为php的CLI安装启用PDO_MYSQL。 I've looked in the php.ini file and there does not appear to be a relevant entry for it. 我查看了php.ini文件,似乎没有相关的条目。

Is there any easy way to make the CLI version use exactly the same configuration of my LAMPP configuration, in order to minimise complications in the future? 是否有任何简单的方法可以使CLI版本使用与我的LAMPP配置完全相同的配置,以便最大限度地减少将来的复杂性?

Any advice would be greatly appreciated. 任何建议将不胜感激。

Thanks. 谢谢。

I'm using ubuntu + mysql (individual install non-lamp) and php cli via apt : 我正在使用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: 这可以从命令行php --ri pdo验证,结果是:

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

To rectify this for mysql , install the php5-mysql module via 为了纠正这种对mysql ,安装php5-mysql通过模块

sudo apt-get install 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 如果您正在使用另一个数据库(例如postgresodbc ),请查找相应的模块名称

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. 检查apache文件夹中的php.ini并将PDO信息复制到php文件夹中的php.ini。

In my lampp configuration I just have 'extension=pdo.so' in php.ini 在我的灯泡配置中,我在php.ini中只有'extension = pdo.so'

I think these answers are a bit old. 我认为这些答案有点陈旧。 Correct answer would be sudo apt-get install php-mysql. 正确的答案是sudo apt-get install php-mysql。 Executing php5-mysql would result in no package found, specially on machines which has php7-cli installed. 执行php5-mysql会导致找不到包,特别是在安装了php7-cli的机器上。 As mentioned problem is that though PDO support is enabled, no driver installed. 如上所述,问题是虽然启用了PDO支持,但未安装驱动程序。 I simply resolved it by executing the above command. 我只是通过执行上面的命令来解决它。

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

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