PDODriver Exception Doctrine无法找到驱动程序

时间:2018-05-20 22:51:51

标签: php mysql symfony pdo doctrine-orm

尝试在Symfony 4和Doctrine中使用pdo_mysql驱动程序时,我运行$entityManager->flush();我得到了An exception occurred in driver: could not find driver

输出:

Doctrine\DBAL\Exception\DriverException:
An exception occurred in driver: could not find driver

  at vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:125
  at Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception occurred in driver: could not find driver', object(PDOException))
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:184)
  at Doctrine\DBAL\DBALException::wrapException(object(Driver), object(PDOException), 'An exception occurred in driver: could not find driver')
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169)
  at Doctrine\DBAL\DBALException::driverException(object(Driver), object(PDOException))
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:47)

.env文件

DATABASE_URL=mysql://USER:PASSWORD!@HOSTNAME/DATABASE

doctrine.yml

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7.21'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

我确保我的docker php-fpm容器有正确的模块。

root@644cfdc6b45b:/usr/local/etc/php/conf.d# php -m | grep -i pdo
PDO
pdo_mysql
pdo_sqlite

我的AWS RDS实例正在运行MySQL 5.7.21。我能够创建和运行实体的迁移,因此bin / console正在运行,但Symfony本身并没有找到合适的驱动程序。任何有助于实现这一目标的提示都非常感谢。谢谢!

以下是我的UserController

<?php

namespace App\Controller;

use App\Entity\User;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;


class UserController extends Controller
{
    /**
     * @Route("/user", name="user")
     */
    public function index()
    {
        $entityManager = $this->getDoctrine()->getManager();

        $user = new User();
        $user->setName('Jay');
        $user->setUsername('testc');
        $user->setEmail('test@test.com');
        $user->setPassword(password_hash('testpassword', PASSWORD_DEFAULT));

        $entityManager->persist($user);

        $entityManager->flush();

        return new Response('Saved new user' . $user->getId());
    }
}

1 个答案:

答案 0 :(得分:0)

我不得不重启我的docker容器来解决这个问题。