为什么 Doctrine 说找不到 PDO 驱动程序?

发布于 2024-12-04 22:26:43 字数 443 浏览 2 评论 0原文

我今天尝试了 Symfony 2,并尝试使用 Doctrine 玩一下。

但是当我在命令行中使用命令 php app/consoledoctrine:schema:create 时,它返回此错误:

[PDOException]
could not find driver

doctrine:schema:create [--dump-sql] [--em[="..."]]

我的 php.ini 文件和 phpinfo() 清楚地显示 PDO 驱动程序已加载。我还用纯 PHP 创建了一个小脚本来使用 PDO 连接到我的数据库,它工作得很好。没有错误,因此 PDO 已正确安装并且可以正常工作。

我的计算机上使用最新版本的 EasyPHP 运行 PHP 和 MySQL。

Doctrine 可能出了什么问题?我现在应该看哪里?

I tried Symfony 2 today and I tried to play a bit with Doctrine.

But when I use the command php app/console doctrine:schema:create in the command line, it returns this error:

[PDOException]
could not find driver

doctrine:schema:create [--dump-sql] [--em[="..."]]

My php.ini file and phpinfo() cleary show that the PDO driver is loaded. I also created a little script in pure PHP to connect to my database using PDO and it worked fine. No error, so PDO is well installed and works.

PHP and MySQL are running on my computer using the last version of EasyPHP.

What could have gone wrong with Doctrine? Where should I look now?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

深白境迁sunset 2024-12-11 22:26:43

是的,如果您在命令行中输入 php -m ,它应该同时列出 PDO 和 pdo_mysql 。就我而言,它仅显示 PDO,这就是它找不到 MySQL 驱动程序的原因。

正如您已经评论过的,我认为这是因为 PHP CLI 找不到合适的 php.ini 文件。

Yeah, if you type php -m at the command line, it should list both PDO and pdo_mysql. In my case it showed only PDO which is why it could not find the MySQL driver.

As you've already commented, I think it's because the PHP CLI cannot find a suitable php.ini file.

梦太阳 2024-12-11 22:26:43

您需要正确配置 php cli,以加载 Web 服务器版本已配置加载的相同扩展。

这是 PHP 搜索配置文件的链接

You need to configure correctly your php cli, to load the same extensions that the web server version has configured to load.

Here is a link on where PHP searches for the configuration file

天赋异禀 2024-12-11 22:26:43

sudo apt-get install php5-mysql

会发挥神奇作用

sudo apt-get install php5-mysql

will do the magic

橘和柠 2024-12-11 22:26:43

在命令行上,检查是否有 PDO 支持:

php -m|grep -i pdo

如果没有,搜索 php mysql 支持(Ubuntu):

apt-cache search php5*|grep mysql

并安装它:

sudo apt-get install php5-mysql

安装 packagem 后再次检查,您应该看到 PDO mysql 支持。

On command line, check if you have PDO support:

php -m|grep -i pdo

If not, search for php mysql support (Ubuntu):

apt-cache search php5*|grep mysql

And install it:

sudo apt-get install php5-mysql

After installing the packagem check again, you should see the PDO mysql support.

网白 2024-12-11 22:26:43

请注意,该错误并不特定于缺少哪个驱动程序。就我而言,我有 PDO 和 PDO_MYSQL,但它还需要 PDO_sqlsrv。

运行 php app/consoledoctrine:schema:create -vvv 以获得更好的细节。

Notice that the error is not specific toward which driver it's missing. In my case, I had PDO and PDO_MYSQL, but it also required PDO_sqlsrv.

Run php app/console doctrine:schema:create -vvv for better specifics.

素衣风尘叹 2024-12-11 22:26:43

就我而言,我尝试从本地终端而不是从 docker 容器运行 bin/console。

也许这会对其他人有所帮助!

In my case, I've tried to run bin/console from a local terminal and not from the docker container.

Maybe it will help the others!

完美的未来在梦里 2024-12-11 22:26:43

如果您在 php 安装中编辑 php.ini,该 .ini 文件是 phpinfo() 中指定的文件,并且您的 php.ini 更改仍然没有显示在 symfony 项目中,您需要创建一个 php.ini在项目的根目录中添加您想要覆盖的值。

扫描此目录以获取其他 .ini 文件现在应该显示您的项目根目录。

解析的其他 .ini 文件 应显示新项目特定的 php.ini 文件。

(我正在本地运行 Symfony 3.3 应用程序)

If you're editing php.ini in your php install, that .ini file is the one specified in phpinfo(), AND your php.ini changes still aren't showing up with a symfony project you need to create a php.ini in your project's root directory and add the values you want to override there.

Scan this dir for additional .ini files should now show your projects root directory.

Additional .ini files parsed should show the new project specific php.ini file.

(I'm getting a Symfony 3.3 app to run locally)

烟花易冷人易散 2024-12-11 22:26:43

就我而言,我在 laravel 7.x 项目中使用以下命令安装了该学说。

composer require doctrine/dbal

所以作曲家在我的laravel 7.x项目中安装了最后一个doctrine/dbal版本,然后出现了这个错误。

所以,也可能是学说/dbal 版本。

In my case, I installed the doctrine with the command bellow, in laravel 7.x project.

composer require doctrine/dbal

So the composer installed the last doctrine/dbal version in my laravel 7.x project, then this error appered.

So, could be the doctrine/dbal version too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文