Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

php - Symfony 3 - An exception occurred in driver: could not find driver

I just try symfony 3 and I am on insert data into database using Doctrine ORM. When I try to run my query

$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 DoctrineDBALExceptionDriverException: "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:

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.

Then add these two lines in php.ini:

extension=pdo.so
extension=pdo_mysql.so

but I still got the same PDO Exception.

My OS is Ubuntu 17.1

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I believe php-mysql package missing in your system. Install the package using the command

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

 sudo service apache2 restart.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...