在symfony4和dority中尝试使用pdo\umysql驱动程序时,我运行 $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
条令.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示例运行的是MySQL5.7.21。我也能够创建和运行实体的迁移,所以bin/console可以工作,但是symfony本身找不到合适的驱动程序。任何有助于这项工作的提示都非常感谢。谢谢!
下面是我的用户控制器
<?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条答案
按热度按时间gpnt7bae1#
我必须重新启动docker容器来解决此问题。