如何为CLI启用PDO_MYSQL? [英] How to enable PDO_MYSQL for CLI?

查看:129
本文介绍了如何为CLI启用PDO_MYSQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习适用于PHP的Symfony框架,但php的命令行版本存在问题。

I'm trying to learn the Symfony framework for PHP but having issues with the command line version of php.

尝试创建数据库表时:

./symfony doctrine:insert-sql

我遇到以下错误:

Couldn't locate driver named mysql

这只是php命令行版本的问题。我的学说没问题。

This is only an issue with the command line version of php. I've had doctrine working no problem.

快速阅读问题之后,似乎我需要为PHP的CLI安装启用PDO_MYSQL。我已经查看了php.ini文件,似乎没有与此相关的条目。

After quickly reading up on the problem, it seems I need to enable PDO_MYSQL for the CLI installation of php. I've looked in the php.ini file and there does not appear to be a relevant entry for it.

是否有任何简单的方法可以使CLI版本完全使用我的LAMPP配置使用相同的配置,以最大程度地减少将来的麻烦?

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?

任何建议都将不胜感激。

Any advice would be greatly appreciated.

谢谢。

推荐答案

我正在使用 ubuntu + mysql (非单独安装)和 php cli 通过 apt

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

sudo apt-get install php5-cli

PDO,但未安装适当的数据库驱动程序(在我的情况下为 mysql )。可以从命令行 php --ri pdo 进行验证,结果为:

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 ]

要针对 mysql 进行更正,通过

sudo apt-get install php5-mysql安装 php5-mysql 模块

sudo apt-get install php5-mysql

显然,在安装 php5-cli 之后执行此操作。如果您正在使用其他数据库(例如 postgres odbc ),请通过

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搜索php5

对不起,< a href = https://stackoverflow.com/questions/6001316/getting-pdo-mysql-driver-to-work-in-cli/7564362#7564362>在这里我的答案。

这篇关于如何为CLI启用PDO_MYSQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆