简体   繁体   中英

Symfony 3 MySQL driver 'could not find driver'

I actualy got some difficulties with Symfony 3 and PDO driver.

It's my first project with Symfony 3 (I used Symfony 2 before that), and when I want to use Doctrine or FOSUserBundle I got this error :

could not find driver

500 Internal Server Error - PDOException

I check what was wrong and I found it's was an error throw by : /path-to-project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql

It's a simple PDOException throw when the PDO class can't access to the Database server. BUT I can execute this code without problem with a "$> php test.php"

$pdo = new PDO("mysql:dbname=Accounting;host=127.0.0.1","<user>", "<secret>");
$sql = 'SELECT * FROM Accounting.fos_user;';
echo count($pdo->query($sql));

And this error is throw by the same code, execute by Symfony 3 (By Doctrine and tested in a simple Controller).


Here are my parameters :

 # app/config/parameters.yml parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: 3306 database_name: Accounting database_user: <user> database_password: <secret> # app/config/config.yml # Doctrine Configuration doctrine: dbal: driver: "%database_driver%" host: "%database_host%" port: "%database_port%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" charset: UTF8 # if using pdo_sqlite as your database driver: # 1. add the path in parameters.yml # eg database_path: "%kernel.root_dir%/data/data.db3" # 2. Uncomment database_path in parameters.yml.dist # 3. Uncomment next line: # path: "%database_path%" orm: auto_generate_proxy_classes: "%kernel.debug%" naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true fos_user: db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel' firewall_name: main user_class: UserBundle\\Entity\\User 

EDIT 29/03/2016

OS Configuration : Ubuntu 14-04 on a VM

I will answer to my own question. This problem happen because I try to use symfony with mysql pdo driver on a container (form a virtualisation). When I use the same setup on a real VM (= fully virtualize virtual machine) It's work correctly. Driver are found and we can create pdo in a Symfony 3 project.

Tested the 10/04/2016

Ty malcolm for the helping, I learn somethings thanks to you :)

Regards, Dykoine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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