Symfony 3 MySQL驱动程序'找不到驱动程序'

时间:2022-09-19 14:46:25

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

我实际上遇到了Symfony 3和PDO驱动程序的一些困难。

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 :

这是我与Symfony 3的第一个项目(之前我使用过Symfony 2),当我想使用Doctrine或FOSUserBundle时,我遇到了这个错误:

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

我检查了什么是错的,我发现这是一个错误抛出:/ 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类无法访问数据库服务器时,这是一个简单的PDOException抛出。但是我可以使用“$> 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).

并且这个错误是由相同的代码抛出的,由Symfony 3执行(By Doctrine并在一个简单的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
        #     e.g. 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

编辑29/03/2016

OS Configuration : Ubuntu 14-04 on a VM

操作系统配置:VM上的Ubuntu 14-04

1 个解决方案

#1


0  

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.

我会回答我自己的问题。出现此问题是因为我尝试在容器上使用symfony和mysql pdo驱动程序(形成虚拟化)。当我在真实VM(=完全虚拟化虚拟机)上使用相同的设置时,它可以正常工作。找到驱动程序,我们可以在Symfony 3项目中创建pdo。

Tested the 10/04/2016

测试了2016年4月10日

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

Ty malcolm的帮助,我学到了一些感谢你:)

Regards, Dykoine

此致,Dykoine

#1


0  

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.

我会回答我自己的问题。出现此问题是因为我尝试在容器上使用symfony和mysql pdo驱动程序(形成虚拟化)。当我在真实VM(=完全虚拟化虚拟机)上使用相同的设置时,它可以正常工作。找到驱动程序,我们可以在Symfony 3项目中创建pdo。

Tested the 10/04/2016

测试了2016年4月10日

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

Ty malcolm的帮助,我学到了一些感谢你:)

Regards, Dykoine

此致,Dykoine