Symfony 5 - "An exception occurred in driver: could not find driver"

Viewed 28355

I'm currently face to this problem. I am really new beginer at Symfony.

Problem : When i create a new db with cli symfony console doctrine:database:create, i am getting these errors :

In AbstractPostgreSQLDriver.php line 102:

  An exception occurred in driver: could not find driver  


In Exception.php line 18:

  could not find driver  


In PDOConnection.php line 38:

  could not find driver

Iam using php 7.4 with xampp and normaly pdo_sql is installed :

extension=bz2
extension=curl
;extension=ffi
;extension=ftp
extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop

this is my .env file config :

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://root:@127.0.0.1:3306/dbname"
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

And this is my doctrine.yaml file config :

doctrine:
dbal:
    url: '%env(resolve:DATABASE_URL)%'
    # IMPORTANT: You MUST configure your server version,
    # either here or in the DATABASE_URL env var (see .env file)
    #server_version: '13'
orm:
    auto_generate_proxy_classes: true
    naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
    auto_mapping: true
    mappings:
        App:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App

I have been searching for hours but i cant get any solutions to solve my problem, someone has an idea ? I'm on windows.

Thanks a lot !

9 Answers

If you want to use Mysql , comment this line DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" If not comment the other line

I'm running Homestead/vagrant on windows and my problem was, I wasn't able to execute this command php bin/console doctrine:database:create on windows even though I opened a terminal as administrator

As seen on these 2 pictures I tried Cmder and Git bash and both of them failed, saying an execption occured in driver: could not find driver

enter image description here

enter image description here

I then solved it by SSH into my vagrant box vagrant ssh navigated to the working symfony folder and ran the command from there php bin/console doctrine:database:create and for some reason that worked !

enter image description here

I wish there was an easier way to debug this stuff, but I guess that's how it is working with Windows. Hope this can help someone out there

php.ini

  1. copy path
  2. find the file then open it
  3. delete the ; in extension=mysqli

modified php.ini file without the ; in extension=mysqli

I also had this problem, just uncomment the DATABASE_URL that you have on your computer either (sqlite, mysql or postresql).

I had the same problem, PHP 7.4.29, xampp, windows.

For the purpose of installing Xdebug I upgraded my PHP version to 7.4.29 (previously 7.4.18), and I guess this errror occured since then. Database connexion worked before. I copied the extensions from the old php.ini to the new one and the error remained.

What resolved the problem : added this line :

extension_dir = "D:\programs\xampp\php\ext"

And activated these extensions :

extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
extension=mbstring
extension=exif
extension=mysqli
extension=pdo_mysql
extension=pdo_sqlite

if you are working in Linux, probably some extensions are missing,run those command


sudo apt-get install php-mysql php-pdo

step 1 => go to Xaamp control panel then click config of Apache

step 2 => click on PHP(php.ini).browse through the file. you can able to see these extensions.

extension=bz2 extension=curl

remove ; from ;extension=pdo_pgsql and save it and close file

step 3 => now come back to your project.click on .env file and comment this line:

DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8"

this works!

In my case, I got my .env.local file from a colleague and stupidly saved it without the leading dot, so Symfony was using the values from the .env file, which reads DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8" rather than the correct DATABASE_URL="mysql://foo:bar@127.0.0.1:3306/baz?serverVersion=mariadb-x.y.z" from .env.local.

I had the same problem when I typed the following command: symfony console make:user User I solved the problem with the command: php bin/console make:user User. Wanting to create a user

Related