cakephp / app

CakePHP application template
374 stars 393 forks source link

Database connection #1022

Open Trylam opened 1 month ago

Trylam commented 1 month ago

Description

I've created a cakephp 5 project with a postgresql database. I configured the database as usual and got this error message : CakePHP is NOT able to connect to the database. SQLSTATE[22023]: Invalid parameter value: 7 ERREUR: valeur invalide pour le paramètre « client_encoding » : « utf8mb4 »

To solve the problem, we had to comment out the line in app.php : 'encoding' => 'utf8mb4', and I don't think it's right that the cakephp system encourages you to use a MariaDB/MySQL database instead of another one. I think that this field should be commented out by default and that it should be up to MariaDB/MySQL users to uncomment it.

CakePHP Version

5.1.1

PHP Version

No response

ADmad commented 1 month ago

Pretty sure MySQL/MariaDB is the most widely used database, so providing default config for it makes things a tad bit easier for users.

The issue is due to the fact that the default datasource config exists in both app.php and app_local.php (generated at project creation time). The driver and encoding is specified in app.php but not in app_local.php. Moving all datasource config to app_local.php would avoid such gotachas.

dereuromark commented 1 month ago

Moving all datasource config to app_local.php would avoid such gotachas.

Having the main (and for all drivers valid) config in app would still be a bit more DRY. To have local file only needed for actual things to overwrite (and usually specific to env).

HumanG33k commented 1 month ago

Can that specific value should not be set by default one "lvl down" (driver or whatever) with the most valid value (utf8mb4). And let it appear in local env file as comment in order to let know people need to change it the option exist.

dereuromark commented 1 month ago

This would revert https://github.com/cakephp/app/pull/1011 I am fine with it, if there is people really bothered by it. At the time it seemed like a good default for the majority - since many use Mysql etc directly in their apps.

The downside of it would be: It will for many not be clear they are silently using utf8 connection. You get a clear error message and know how to fix things, the other direction usually not.