开发者

Why does Doctrine say it can't find the PDO driver?

I tried Symfony 2 today and I tried to play a bit with开发者_C百科 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?


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.


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


sudo apt-get install php5-mysql

will do the magic


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.


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!


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)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜