symfony 4: An exception occurred in driver: could not find driver

13,004

Looks like you are missing the PDO mysql extension.

Try to install it like below :

If you are running linux with apache2 do the following:

apt-get install php-mysql

After the above command has finished edit you php.ini file like so :

  • Search for pdo_mysql extension

It will be something like this

;extension=pdo_mysql.so

Change this line to this:

extension=pdo_mysql.so

And after changing php.ini file, restart apache service like this:

service apache2 restart

PS: you may need to use sudo

Share:
13,004
user1748166
Author by

user1748166

Updated on June 05, 2022

Comments

  • user1748166
    user1748166 almost 2 years

    Working with Doctrine DBAL in Symfony 4 with the following conofiguration (doctrine.yaml):

    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
    
        url: '%env(resolve:DATABASE_URL)%'
        driver_class: App\DBAL\Driver\PDOMySql\Driver
    

    and .env:

    DATABASE_URL=mysql://root:[email protected]:3306/dbname
    

    we are unable to connect to the database via DBAL:

    $conn = DriverManager::getConnection(Constants::connectionParams,new Configuration());
    

    Getting An exception occurred in driver: could not find driver exception. I haven't found documentation about that error in this version in S4.

    • Paul Bönisch
      Paul Bönisch about 5 years
      Have you enabled php pdo extensions?