php Symfony 3 - 驱动程序发生异常:找不到驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47113015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony 3 - An exception occurred in driver: could not find driver
提问by Ricardo Raz
I just try symfony 3 and I am on insert data into database using Doctrine ORM. When I try to run my query
我只是尝试了 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();
but it returns an exception :
但它返回一个异常:
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
Parameters.yml:
参数.yml:
parameters:
database_host: 127.0.0.1
database_port: null
database_name: practice
database_user: root
database_password: null
Config.yml
配置文件
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
I also check if the extension is enabled and loaded via php -m and phpinfo(). It says that PDO & PDO_Mysql is enabled.
我还检查扩展是否通过 php -m 和 phpinfo() 启用和加载。它说 PDO & PDO_Mysql 已启用。
Then add these two lines in php.ini:
然后在php.ini中加入这两行:
extension=pdo.so
extension=pdo_mysql.so
but I still got the same PDO Exception.
但我仍然得到相同的 PDO 异常。
My OS is Ubuntu 17.1
我的操作系统是 Ubuntu 17.1
采纳答案by Ricardo Raz
I just solved my problem by just restarting my OS.
我刚刚通过重新启动我的操作系统解决了我的问题。
回答by Nightfox
I believe php-mysql package missing in your system. Install the package using the command
我相信您的系统中缺少 php-mysql 包。使用命令安装包
sudo apt-get install php-mysql
I hope this will fix your issue.
我希望这会解决您的问题。
I think you need to restart Apache also in order to fix the issue. After installing php-mysql use the following command to restart Apache
我认为您还需要重新启动 Apache 才能解决此问题。安装 php-mysql 后使用以下命令重启 Apache
sudo service apache2 restart.
回答by Ricardo Raz
First of all you have to change MySQL port number from null
to 3306
. That's it.
I think you don't have MySQL password that's why you didn't write anything.
首先,您必须将 MySQL 端口号从 更改null
为3306
. 就是这样。我认为您没有 MySQL 密码,这就是您没有写任何内容的原因。
Have a good day.
祝你有美好的一天。
回答by Harry Wagstaff
On my system (Fedora), a package called php-mysqlnd was required. I installed it by running:
在我的系统 (Fedora) 上,需要一个名为 php-mysqlnd 的包。我通过运行安装它:
dnf install php-mysqlnd
回答by MRustamzade
In my case (in windows) i have installed mysql driver.
就我而言(在 Windows 中)我已经安装了mysql 驱动程序。
回答by Vikas Khatana
For me I added these 2 lines in /etc/php/5.6/cli/php.ini
as they were already present in
对我来说,我添加了这两行,/etc/php/5.6/cli/php.ini
因为它们已经存在于
/usr/lib/php/5.6/php.ini-development
/usr/lib/php/5.6/php.ini-development
extension=pdo.so
extension=pdo_mysql.so
Then did:
然后做了:
sudo service apache2 restart
I could then flush entity to database.
然后我可以将实体刷新到数据库。
Hope this works for anyone else in future.
希望这对未来的其他人有用。
回答by Vael Victus
In WAMPServer and possibly other configurations, there may be a separate php.ini
for your command line PHP. Ensure that you enabling your modules in the right .ini (ideally both ini's)
在 WAMPServer 和可能的其他配置中,可能有单独php.ini
的命令行 PHP。确保在正确的 .ini 中启用模块(最好是两个 ini)