user1748166
user1748166

Reputation: 147

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

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.

Upvotes: 2

Views: 13493

Answers (1)

M. Xhafa
M. Xhafa

Reputation: 79

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

Upvotes: 7

Related Questions