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

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 !

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

if you are working in Linux, probably some extensions are missing,run those command
sudo apt-get install php-mysql php-pdo

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

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'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
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 !
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
copy path
find the file then open it
delete 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 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

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!

I had the same problem, I am runing a Symofny application with docker.
When you add doctrine-bundle to your app, in Dockerfile will appear this lines what will install drivers for postgres.
You have to remove it and add this line, this will install drivers for mysql
RUN docker-php-ext-install pdo pdo_mysql
I hope that helps to someone.

Delete or comment from .env file the line:
DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"

I had the same problem to solve the problem:
type php --ini to see the path to the file php.init
if you are on vscode do ctr + click on the path otherwise follow the path manually on your computer to the file php.init make sure your open php.init file with admin right !!
edit the file and uncomment extension=pdo_mysql
save and retry php bin/console doctrine:database:create
type php -m for check if your're in list pdo_mysql
here an illustration

Related

Laravel failed to listen on 127.0.0.1:8000 (reason ?)

So I just created a new project using the command:
laravel new blog
Then I started by changing the directory and do the command
php artisan serve
And this is what happened, more details:
I'm using laravel 8.0.1 (latest version)
I haven't run any command except the one I listed above
I'm using windows
I even updated the php to 7.4.10 (latest ver)
I came across the same issue.
This was how how I solved mine:
Goto the main PHP part, I mean the installed PHP from official website.
Look out for a folder named php.ini-development
Duplicate this file.
Then rename the copy to php.ini
Go back to your laravel project folder and rerun php artisan serve
PS: If there is any additional steps you took, you can as well comment them below:
XOXO
So actually i dont actually know what the reason is, but using the php -S localhost:8000 -t public
Check your PHP version in your local server and System variable path. Make sure they are using the same PHP version
I had this problem too, and I solved it in this way:
set: php.ini
variables_order = "GPCS"
This error is because the php.ini was not found.
run php --ini
Configuration File (php.ini) Path:
Loaded Configuration File: C:\php8\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
The line "Loaded Configuration File" would indicate the location of loaded php.ini, if not, rename the php.ini-development to php.ini

Can not connect to Db- Dump using codeception

I am struggling to use the db functionality of codeception framework. The error i am getting is
Db: could not find mysql driver while creating PDO connection
actor: AcceptanceTester
modules:
enabled: [Db, PhpBrowser]
config:
Db:
dsn: "mysql:host=localhost;dbname=my_db"
user: 'root'
password:
populate: true
cleanup: true
dump: 'tests/_data/Dump20180423.sql'
PhpBrowser:
url :
My acceptance.suite.yaml file is set like this.
Also my dump file has the CREATE TABLE command inside.
The path for Mysql is already set in the environmental variables path.
The pdo extensions are set inside my php.ini file
I guess it's a problem with the dsn as it fails before validating my user credentials. Also my mysql works fine. I have projects that i use PDO connection and they work without any issue.
I tried every solution i could find but still getting the same error. Thank you in advance for any help!!!
So after many hours/days i finally found out the solution to this. The problem was coming from my cygwin (linux console). While my php.ini file was fine and php info was sawing i had pdo_mysql installed and everything seemed like that, cygwin had a different opinion. I had to install pdo_mysql inside cygwin so the command :
php vendor/bin/codecept run could connect to the database and work!!!
Typing php -m in my cygwin console showed me that i was missing this module (pdo_mysql).
After that the problem is solved and my tests work fine.

The local psql command could not be located

I'm following the instructions found here.
When I try to run $ heroku pg:psql or $ heroku pg:psql HEROKU POSTGRESQL_BROWN I recieve the following error message:
! The local psql command could not be located ! For help
installing psql, see local-postgresql
I can't find anything useful on the link it gives me (it just links to the instructions I was already using, but further down the page) nor can I find this error anywhere else.
If I've missed anything you need to know to answer this, just let me know. I'm rather new to all this and teaching myself as I go.
I had same error even after installing Postgres locally.
But after seeing this
I saw that "pqsl" was not in the PATH so I then did
PATH=%PATH%;C:\Program Files\PostgreSQL\9.2\bin
which worked for me
I have since solved this myself. When I ran heroku pg:info it says the version number is 9.1.8, I was locally running 9.2
installing 9.1.8 and ensuring Path pointed to the appropriate folder solved the problem.
After you change the path, make sure to restart the terminal!
Set the PATH. To find out the PATH of your psql script (on mac) open the sql shell script from your finder in Applications/Postgres installation. This will give you a hint as to where it is installed. That opened a window which told me it is located here: /Library/PostgreSQL/8.4/scripts/runpsql.sh
Then, I set the PATH variable from the terminal window by typing:
$ PATH="/Library/PostgreSQL/8.4/bin:$PATH"
(depends on the location of your PostgreSQL installation, find your bin path first, another exp: /usr/local/Cellar/postgresql#9.6/9.6.8/bin)
OR.....
You can also connect to the shell by opening the shell directly from your postgres installation folder. Then enter the credentials. If you don't know the credentials, here is how to find them out:
$ heroku pg:info
=== HEROKU_POSTGRESQL_RED_URL (DATABASE_URL)
$ heroku pg:credentials HEROKU_POSTGRESQL_RED_URL
Top answer wouldn't work for me oddly, my system would not add the Path via cmd with administrator access (Not sure why).
So check this > Windows key > environment variables > system variables
And add the last line (your version may differ in the path)
Make sure you've installed the toolbelt as psql is installed by default.
However you also need to ensure you've installed a local copy of PostgreSQL; if you don't the toolbelt will be unable to find the native psql client.
Assuming you have installed a local copy of PostgreSQL, make sure you can execute psql from the command line directly (i.e make sure you PATH is set correctly ). If the command does not execute, check your PATH, if it does execute see if you can connect via the PSQL connection string provided in the Heroku control panel. If you can connect reinstall the toolbelt, if you are unable to connect provision another dev database and try again.
If there are still issues, I would suggest contacting Heroku support for assistance after verifying no API issues are listed on the status page located here.
I got rid if this annoying message on Windows by adding a path element without the spaces, i.e.
C:\Progra~1\PostgreSQL\9.4\data
instead of
“C:\Program Files\PostgreSQL\9.4\data”
I followed the instructions here: http://www.computerhope.com/issues/ch000549.htm, which worked for me if you prefer to go the point-and-click configuration of the PATH variable.
This type of error usually appears in the Windows environment, because if you do not update the PATH after installing Postgresql, heroku pg:psql command does not work.
So you need to update your PATH environment variable to add the bin directory of your Postgres installation. The directory will look like this:
C:\Program Files\PostgreSQL\<VERSION>\bin.
For more information, go to the Heroku in Local setup website:
heroku-postgresql: Local setup
I had the same problem and discovered that Heroku doesn't seem to provision the latest version of PostgreSQL by default. Where the Heroku Getting Started instructions said
heroku addons:create heroku-postgresql:hobby-dev
That provisioned a v10 database for some reason (which you can check by clicking on Heroku Postgres in the Add-ons tab of your dashboard). I deleted that database and provisioned a new database using the --version flag:
heroku addons:create heroku-postgresql:hobby-dev --version 11
As of now, at least, you can find the latest version of Postgres supported by Heroku at this link: https://devcenter.heroku.com/articles/heroku-postgresql#version-support-and-legacy-infrastructure
I'm writing this in early 2019, but according to the PostgreSQL website the next version (12) is "tentatively scheduled" for third quarter of 2019 so if you're reading this in late 2019 potentially the same problem will come up for v12 instead
On Mac you can use the following:
export PATH="/Library/PostgreSQL/12/bin/:$PATH"
The only solution that I found on Windows:
go to advanced system settings
go to environment variables
select Path variable and click Edit
add a new line and enter your bin directory path (C:\Program Files\PostgreSQL<version>\bin) and click ok
restart your terminal
enter your psql command (heroku pg:psql)

Symfony2 Sonata admin make apache goes down on Windows 7

I'm learning Symfony and installed Sonata Admin Bundle. After opening /admin/login/ first time it opens, but after reload apache goes down. So after every page reload I need to restart apache.
I think it's my code bug, so installed working site on my local, but got same problem.
Don't know what info is important to put with question, please let me know and I'll update question.
UPDATE:
I got perl error:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = (unset),
LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Can find solution for Linux, need to run this commands:
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
apt-get install locales
dpkg-reconfigure locales
But nothing for Windows 7.
Also some solutions on StackOverflow:
How to fix a locale setting warning from Perl?
Solution
Problem was in APC extension, you can disable it on your dev server, because it just extension for cahce. Works for me without it.

Apache and Sqlite3 issue

I'm using ports only on this server. After restarting apache I got "segment fault (core dumped)" message. But apache is started at least... httpd-error.log shows this:
profiling:/usr/ports/databases/sqlite3/work/sqlite-3.7.3/.libs/sqlite3.gcda:Cannot open
profiling:/usr/ports/databases/sqlite3/work/sqlite-3.7.3/.libs/sqlite3.gcda:Cannot open
profiling:/usr/ports/databases/sqlite3/work/sqlite-3.7.3/.libs/sqlite3.gcda:Cannot open
profiling:/usr/ports/databases/sqlite3/work/sqlite-3.7.3/.libs/sqlite3.gcda:Cannot open
Listing of that dir:
baccy# ls /usr/ports/databases/sqlite3/work/sqlite-3.7.3/.libs/
libsqlite3.a libsqlite3.la libsqlite3.lai libsqlite3.so libsqlite3.so.8 sqlite3 sqlite3.gcno sqlite3.o
On this system I've got redmine installed, that's why sqlite is included in here.. now I installed django and I need sqlite3 so much..
It would be nice to know, WHY this error appears, and HOW to handle this =)
Just found an answer
it's GCONV param fault... just go to /usr/ports/databases/sqlite3 and then make config, and remove GCONV param.