To configure the database connection both files, config.yml and paramters.yml are used (see also the Symfony Documentation). While the config.yml file contains only the placeholders, the values for the database connection are placed in the paramters.yml.
You can find examples for the Configuration in our Installation Instructions, for example in the chapter Configuration of Mapbender3 on Ubuntu and Debian.
In Mapbender3 we use Doctrine which is a set of PHP libraries and offers an Object Relational Mapper and a Database Abstraction Layer. Visit the Doctrine project page and read more.
The standard database definition in the config.yml looks like this:
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
path: %database_path%
user: %database_user%
password: %database_password%
charset: UTF8
logging: %kernel.debug%
profiling: %kernel.debug%
orm:
auto_generate_proxy_classes: %kernel_debug%
auto_mapping:true
All values encapsulated in % are parameters, loaded from the parameters.yml. The parameters.yml will load these parameters. Therefore, to change the database, modify the parameters values in the parameters.yml.
Please keep in mind, that you have installed resp. activated the appropriate PHP-driver.
Using multiple databases is easy with Mapbender3 and advised if you want to separate your own data from Mapbender’s. This is useful in a scenario where you have your own custom code provided by an non-Mapbender bundle.
There’s always a default database connection and all Mapbender code assumes that it can access it’s data using that default database connection.
So if your code wants to use a different database you have to define a second named database connection and always use that named database connection.
Here is an example for a database connection block in the config.yml with two connections:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
path: %database_path%
user: %database_user%
password: %database_password%
charset: UTF8
logging: %kernel.debug%
profiling: %kernel.debug%
search_db:
driver: %database2_driver%
host: %database2_host%
port: %database2_port%
dbname: %database2_name%
path: %database2_path%
user: %database2_user%
password: %database2_password%
charset: UTF8
logging: %kernel.debug%
profiling: %kernel.debug%
The definition of the database variables is done in the file parameters.yml.
parameters:
# database-connection "default"
database_driver: pdo_pgsql
database_host: localhost
database_port: 5432
database_name: mapbender3
database_path: ~
database_user: postgres
database_password: postgres
# database-connection "search_db"
database2_driver: pdo_pgsql
database2_host: localhost
database2_port: 5432
database2_name: search_db
database2_path: ~
database2_user: postgres
database2_password: postgres