Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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:

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

like image 715
Ricardo Raz Avatar asked Nov 04 '17 16:11

Ricardo Raz


2 Answers

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.
like image 122
Nightfox Avatar answered Nov 09 '22 20:11

Nightfox


For me I added these 2 lines in /etc/php/5.6/cli/php.ini as they were already present in

/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.

like image 3
Vikas Khatana Avatar answered Nov 09 '22 20:11

Vikas Khatana