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

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...