gpt4 book ai didi

php - Symfony 3 - 驱动程序 : could not find driver 发生异常

转载 作者:可可西里 更新时间:2023-11-01 06:59:36 31 4
gpt4 key购买 nike

我只是尝试 symfony 3,我正在使用 Doctrine ORM 将数据插入数据库。当我尝试运行查询时

$customer = new Customer();
$customer->setAddress('Some Address');
$customer->setName('Customer 1');

$order->setQuantity('100');
$order->setDate(date('Y-m-d'));
$order->setCustomer($customer);

$em = $this->getDoctrine()->getManager();
$em->persist($customer);
$em->persist($order);
$em->flush();

但它返回一个异常:

Uncaught PHP Exception Doctrine\DBAL\Exception\DriverException: "An exception occurred in driver: could not find driver" at /home/hei/Sites/practice/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 121

参数.yml:

parameters:
database_host: 127.0.0.1
database_port: null
database_name: practice
database_user: root
database_password: null

配置.yml

doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'

我还通过 php -m 和 phpinfo() 检查扩展是否已启用和加载。它说 PDO 和 PDO_Mysql 已启用。

然后在php.ini中加入这两行:

extension=pdo.so
extension=pdo_mysql.so

但我仍然遇到相同的 PDO 异常。

我的操作系统是 Ubuntu 17.1

最佳答案

我相信你的系统中缺少 php-mysql 包。使用命令安装包

sudo apt-get install php-mysql

我希望这能解决您的问题。

我认为您还需要重新启动 Apache 才能解决此问题。安装php-mysql后使用以下命令重启Apache

 sudo service apache2 restart.

关于php - Symfony 3 - 驱动程序 : could not find driver 发生异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47113015/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com