most of the time you need to set the following variables:
doctrine: dbal: dbname: database host: localhost port: 1234 user: user password: secret driver: pdo_mysql server_version: '5.6' charset: UTF8 url: mysql://db_user:email@example.com:3306/db_name
there are quite a lot settings to configure doctrine in symfony. if you want to be flexible, your .env file or your
environment variables get increased by many variables.
the main problem is that if you want to use sqlite for tests and mysql for dev & prod you need to define the
server_version. where sqlite needs
UTF8 and mysql
UTF8MB4. also mysql needs the
an important info is, that url overwrites all other settings. so if your url starts with
mysql: you don't need to set
A URL with connection information; any parameter value parsed from this string will override explicitly set parameters
Configuration.php of doctrine-bundle
a thing which is well hidden, is that doctrine supports query parameters, so you can reduce the config to this:
with this dotenv setting you also set the charset and the server version
so the other settings from above are reduced to this:
doctrine: dbal: url: '%env(resolve:DATABASE_URL)%'
- cover image by MasterTux https://pixabay.com/photos/adventure-treasure-map-old-world-map-2528477/
This series of posts document a high-level process to use when planning a modern web application, from project organization, collaboration considerations and tooling choices during development, all the way through deployment and performance strategies.