14

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

1
  • Do you have same php version for cli and web? Create script <?php phpinfo(); and check if mysql extensions is available there Commented Nov 4, 2017 at 18:04

6 Answers 6

33

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. 
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

On my system (Fedora), a package called php-mysqlnd was required. I installed it by running:

dnf install php-mysqlnd 

Comments

0

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.

Have a good day.

1 Comment

The "null" on the port parameter it means that you're using the default port "3306", so I don't think that this will solve the problem, I think there is a problem related to the mysql driver extension on php.ini
0

In my case (in windows) i have installed mysql driver.

Comments

0

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.