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.
Related
I have a problem connecting from eZPlatform 3.0 (based on Symfony 5) to the Azure MySQL database.
I get the error:
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL
options and retry.
Configuration is as follows:
doctrine:
dbal:
# configure these for your database server
driver: '%database_driver%'
charset: '%database_charset%'
default_table_options:
charset: '%database_charset%'
collate: '%database_collation%'
url: '%env(resolve:DATABASE_URL)%'
options:
!php/const:PDO::MYSQL_ATTR_SSL_CA: '%ca_cert%'
!php/const:PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT : false
Strange thing is that this happens when I visit the route /admin, on homepage I don't get that exception.
The Problem
I have a fresh setup of postgres 10.5 and symfony 4 application running on php 7.1. But when I try running migration. I keep getting the following Invalid value for parameter "client_encoding": "utf8mb4" error.
Steps to reproduce
On .env file by modify DSN to correct value based on the your settings for eg. mine wasDATABASE_URL="pgsql://postgres:password#db:5432/a_db".
Create an entity (Any would do) using php bin/console make:entity
Make Migration file php bin/console make:migration
Expected Result
I should have received Success message.
So my Question is
What did I miss here as I have followed the documentation?
So my actual client config in the postgres is utf8 not utf8mb4. It seems symfony does not automatically detects the version and database for us.
Symfony 4 has left the standard utf8mb4 for MYSQL in the config file config/packages/doctrine.yaml. This configuration file should not be forgotten to change based on these allowed configuration. So the problem was fixed when I changed the value
from
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
to
dbal:
driver: 'pdo_postgresql'
server_version: '10.5'
charset: utf8
default_table_options:
charset: utf8
collate: utf8_unicode_ci
For me it helped to add the encoding to the Database URL, like this:
postgres://api-platform:!ChangeMe!#db/api?charset=UTF-8
Though this problem only occurred in APP_ENV=prod.
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.
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.
I can't found a way to setup Symfony with a postgresql database on OS X 10.10 (clean install). Here is what I have done:
1) Install PHP 5.6 from Liip (specially built for Symfony): http://php-osx.liip.ch/
2) Install Postgres.app: http://postgresapp.com/
3) Install Symfony: http://symfony.com/
4) Setup my parameters.yml
parameters:
database_driver: pdo_pgsql
database_host: 127.0.0.1
database_port: 5432
database_name: bachelor
database_user: username
database_password: ~
I have created the DB, verified that I have the right PHP cli, the right pgql cli, etc.
I have created a bundle in Symfony and some entities (no errors here, it works with MySQL).
But when I launch any command to interact with the DB like "php app/console doctrine:schema:update --dump-sql", I have this error:
[PDOException]
SQLSTATE[HY000] [2006] MySQL server has gone away
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: PDO::__construct(): MySQL server has gone away
But why? I don't use a MySQL server...
Does someone have any solution?
Thanks!
Can you show us your /app/config/config.yml ? please
Did you change the dbal connection value ?
# Doctrine Configuration
doctrine:
dbal:
default_connection: pgsql
connections:
#Postgresql
pgsql:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8