Can't create database with Symfony 4.1 : could not find driver - php

When i do the command php bin/console doctrine:database:create i have these errors :
In AbstractMySQLDriver.php line 126: An exception occurred in
driver: could not find driver
In PDOConnection.php line 50: could not find driver
In PDOConnection.php line 46: could not find driver
config/packages/doctrine.yaml
doctrine:
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
.env
DATABASE_URL=mysql://root:root#127.0.0.1:3306/blogMyProject
My PHP Extensions:
php.ini extensions:
PHP 7.2.7 - MySQL 5.7.11 - Symfony 4.1.4 - I use UwAmp 3.1.0 - I'm on Windows
I don't understand where these errors come from.

This works for my case
symfony 4.2
php 7.3
I enabled
extension=pdo_mysql
in php.ini

in file=> config\packages\doctrine.yaml
dbal:
dbname: database
host: localhost
port: 1234
user: user
password: secret
driver: pdo_mysql
# if the url option is specified, it will override the above config
url: mysql://db_user:db_password#127.0.0.1:3306/db_name
# the DBAL driverClass option
driver_class: App\DBAL\MyDatabaseDriver

RiggsFolly brought the solution :
I have a second php.ini file in UwAmp. The extension pdo_mysql was disabled in bin/php/php-version/php.ini

I have just installed UwAmp 3.1.0 on a Windows 10 machine, and faced this same issue when trying to run the php artisan migrate command on a Laravel app. Here's how I solved it:
Go to bin/php/<php-version>
Make a copy of php_uwamp.ini named php-cli.ini
Open it on a text editor
Replace extension_dir = "{PHPEXTPATH}" by extension_dir = "ext"
Replace zend_extension = "{PHPZENDPATH}/php_xdebug.dll" by extension_dir = "../zend_ext/php_xdebug.dll"
Every time you change PHP Config on UwAmp interface, you must repeat these steps, since the changes are stored on php_uwamp.ini.

in the file php.ini there is the extension extension=pdo_mysql that is disabled. I enabled it and the connection worked.

Related

Symfony 5, problem with doctrine for migration to database mariadb

I have a problem with symfony 5.
When I execute the command: php bin/console doctrine:migrations:migrate
I have an error:
In MetadataStorageError.php line 13: The metadata storage is not up to
date, please run the sync-metadata-storage command to fix this issue.
and I modify my env.local to specify the server version with MariaDB:
DATABASE_URL=mysql://db_user:.......#127.0.0.1:3306/bundletest?serverVersion=mariadb-10.5
and when I execute: php bin/console doctrine:migrations:migrate
I have another error:
In DBALException.php line 86:
Invalid platform version "mariadb-10.5" specified. The platform version has to be specified in the format:
"^(?:5.5.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>".
Setting up doctrine migrations
same way to configure postgres and mysql (need to set different PDO driver of course, server version)|
here is tested & working example up to symfony 5.2 & PHP 7.4
you need two things to update in your project
after instaling doctrine you got new config file
project_dir/config/packages/doctrine.yaml
please set is as below
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
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
and in your .env file
#DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name"
uncoment, set your user and db settings, add ?serverVersion
DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7
run
php bin/console doctrine:database:create (it is better to create db with your project config settings)
and now you are free tu use migrations

Symfony 4 Doctrine not working from console [2002] No such file or directory

I´m working with symfony 4 and this error ocurr when runnning doctrine console commands:
In AbstractMySQLDriver.php line 108:
An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory
I think this is because there´s something wrong with the connection but when I run the application it has access to the database without errors, so I can not imagine what is wrong with the connection.
I was able to continue working by creating manually the database and using
php bin/console doctrine:schema:create --dump-sql
But this is really unwanted because later when the schema needs to be updated all data would be lost because i would need to re-create the schema instead of updating it.
The app works normally after executing manually the SQL (easyadmin works fine).
Here are my configurations:
.ENV:
DATABASE_URL=mysql://root:root#127.0.0.1:3306/test
doctrine.yaml:
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
I tried the drop command just to test and it throwed this:
In DropDatabaseDoctrineCommand.php line 93:
Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.
So I add dbname to doctrine.yaml and didn´t worked.
I also tried removing the cache, creating a new project, using a remote mysql, and using sqlite but the errors are the same in both cases !!
Thanks in advance for the help !
Please change DB_HOST=localhost to DB_HOST=127.0.0.1
> doctrine/doctrine-bundle
DATABASE_URL=mysql://${DB_USER}:${DB_PASSWORD}#${DB_HOST}:${DB_PORT}/${DB_NAME}
So i suppose that you showed the whole content of your doctrine.yml.
If so, you might want to consider changing your doctrine.yml as follows:
add an additional line in the dbal: section
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
url: '%env(resolve:DATABASE_URL)%'
Watch the last line, beginning with url:, closely.
The 'resolve:" operator looks up DATABASE_URL in your env-Variables and if it is found, it then replaces the expression with its content.
This is a doctrine.yml, that gets auto-generated by symfony.
The 'resolve' operator migth not be needed though. This could potentially work too:
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
url: '%env(DATABASE_URL)%'
This method is proposed in the symfony docs, which might be interesting to read, to understand further configuration of symfony.
My fix is here:
export DATABASE_URL=<value from .env>
And generating SQLs works :)
config/packages/doctrine.yaml
I solved this error adding my database url in the "config/packages/doctrine.yaml" file the "parameters" > "env(DATABASE_URL)" field:
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): 'mysql://your_db_url'
I solved this change in .env file
DATABASE_URL=mysql://root:root#127.0.0.1:3306/test
to
DATABASE_URL="mysql://root:root#127.0.0.1:3306/test"
I added quotes. Maybe you are using windows? It works for me.
like in Symfony docs: Environment Variables
Hi On my side I add the exact same behaviour, on symfony 4,
I just changed this
DATABASE_URL=mysql://root:root#localhost:8889/
to this
DATABASE_URL=mysql://root:root#127.0.0.1:8889
on my .env or .env.dev file (depend on the env you are working on)
hope it helps.

Connection to a db with Doctrine pdo_sqlsrv

I'm trying to connect to my database in SQL Server 2000, but i get an error
could not find driver
when i'm using pdo_sqlsrv.
But if i use sqlsrv i get an error
Attempted to call function "sqlsrv_configure" from namespace
"Doctrine\DBAL\Driver\SQLSrv".
Here is my config.yml
config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
host: "%database_host%"
driver: pdo_mysql
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
connection2:
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
host: "%database_host2%"
driver: pdo_sqlsrv
#driver: sqlsrv i've also tried this
#charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
Does anybody know why i'm getting these errors?
If the function sqlsrv_configure can't be found, then the sqlsrv extension isn't installed. It can be found on the official Microsoft repository here.
You can check if you've installed the extension by running the command php -m in your terminal. Note that if you're running Symfony on a standalone server (eg MAMP, XAMP, or anything else that uses a non-CLI version of PHP) then the extensions used by the CLI and the standalone server may differ.
You can test this by going to the profiler in Symfony (/_profiler by default) and clicking on the "View full PHP configuration" link under the Configuration menu item. This will open the phpinfo() screen. Look for either the sqlsrv or pdo_sqlsrv extensions there.
EDIT
Looking at the Doctrine docs again, it seems that pdo_sqlsrv causes problems. Doctrine recommends using sqlsrv.
pdo_sqlsrv: A Microsoft SQL Server driver that uses pdo_sqlsrv PDO Note that this driver caused problems in our tests. Prefer the sqlsrv driver if possible.
(Emphasis not mine)
Can you try:
driver: pdo_sqlsrv
database_port: 1433
Not sure if that will work, but try it.

Symfony - How to connect to remote mysql database without install mysql-server

I am trying to connect to a remote mysql database with my Symfony application. I don't want to install the mysql-server package on my server if I don't need to but when I try to connect, I get the following error:
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] No such file or directory
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
Here's what my database configuration look like. In the variables, I setup pdo_mysql as the driver and the other fields are working well.
doctrine:
dbal:
default_connection: default
connections:
default:
driver: %database.driver%
host: %database.host%
port: %database.port%
dbname: %database.name%
user: %database.user%
password: %database.password%
charset: UTF8
Edit1: If I install mysql-server, it works and the error is gone.
Edit2: My server is running Ubuntu 16.04.2 LTS
You should be able to install client on Ubuntu like this:
apt-get install mysql-client
I think 5.5 is the latest.
Go here for setting up MariaDB:
https://downloads.mariadb.org/mariadb/repositories/#mirror=syringa&distro=Ubuntu
makes more sense nowadays to use MariaDB instead:
EDIT #2
to add remote useron the remote system:
CREATE USER 'fooUser'#'192.168.40.200' IDENTIFIED BY 'myPassword';
check the user table to see if they can connect from remote system:
use mysql;
SELECT Host,User,Password,ssl_type from user;
ssl_type is if you are using SSL to connect, you could leave that out.

pdo_pgsql could not find driver symfony2 + php problems

I hope you're all good because i'm not, I have some trouble understand how Symfony 2 does work and I too have a extension problem (Could not find driver).
Firstly, php --ini tells me I have to edit my /etc/php.ini file BUT in my SF2 setting, i'm using Php 7.0.0 from MAMP, using /Applications/MAMP/.../php.ini and /Application/MAMP/../bin/php. So I should be using php 7.0.0 from MAMP shouldn't I ?
My web/config.php tells me "Set "xdebug.max_nesting_level" to e.g. "250" in php.ini* to stop Xdebug's infinite recursion protection erroneously throwing a fatal error in your project."
But i don't have any "xdebug.max" in my /etc/php.ini neither in my /Application/Mamp/../php.ini (I still don't know which one is used ... The one from my MAC or from Mamp ? Meh i'm so lost !)
That's my first problem, knowing which php.ini is used and why it appears to be the one in /etc.
Secondly, i've a "Could not find driver" error when i'm trying to generate bundle with php app/console doctrine:database:create
I searched on stackoverflow but all I found is that i had to check my phpinfo(); which says me that pdo_pgsql is enabled, then I went in /etc/php.ini and MAMP/php.ini to find the ";extension : pdo_pgsql" to uncomment but they already were ... So what's wrong ?
I'm trying to use postgreSQL database with SF2 and edited my config.yml and parameters.yml correctly I think. Here is my config.yml :
doctrine:
dbal:
driver: pdo_pgsql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
Well if anyone could help it'd be really cool, i don't understand why i have so much trouble understanding SF2.
I absolutly need to know how to use php from MAMP.

Categories