![]() |
|
The symfony Reference BookThe databases.yml Configuration File |
|
You are currently reading "The symfony Reference Book" which is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License license.

|
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |
The databases.yml configuration allows for the configuration of the
database connection. It is used by both ORMs bundled with symfony: Propel and
Doctrine.
The main databases.yml configuration file for a project can be found in
the config/ directory.
Most of the time, all applications of a project share the same database. That's why the main database configuration file is in the project
config/directory. You can of course override the default configuration by defining adatabases.ymlconfiguration file in your application configuration directories.
As discussed in the introduction, the databases.yml file is
environment-aware, benefits from
the configuration cascade mechanism,
and can include constants.
Each connection described in databases.yml must include a name, a database
handler class name, and a set of parameters (param) used to configure the
database object:
CONNECTION_NAME:
class: CLASS_NAME
param: { ARRAY OF PARAMETERS }
The class name should extend the sfDatabase base class.
If the database handler class cannot be autoloaded, a file path can be
defined and will be automatically included before the factory is created:
CONNECTION_NAME: class: CLASS_NAME file: ABSOLUTE_PATH_TO_FILE
The
databases.ymlconfiguration file is cached as a PHP file; the process is automatically managed by thesfDatabaseConfigHandlerclass.
The database configuration can also be configured by using the
database:configuretask. This task updates thedatabases.ymlaccording to the arguments you pass to it.
Default Configuration:
dev:
propel:
param:
classname: DebugPDO
test:
propel:
param:
classname: DebugPDO
all:
propel:
class: sfPropelDatabase
param:
classname: PropelPDO
dsn: mysql:dbname=##PROJECT_NAME##;host=localhost
username: root
password:
encoding: utf8
persistent: true
pooling: true
The following parameters can be customized under the param section:
| Key | Description | Default Value |
|---|---|---|
classname |
The Propel adapter class | PropelPDO |
dsn |
The PDO DSN (required) | - |
username |
The database username | - |
password |
The database password | - |
pooling |
Whether to enable pooling | true |
encoding |
The default charset | utf8 |
persistent |
Whether to create persistent connections | false |
options |
A set of Propel options | - |
Default Configuration:
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql:dbname=##PROJECT_NAME##;host=localhost
username: root
password:
attributes:
quote_identifier: false
use_native_enum: false
validate: all
idxname_format: %s_idx
seqname_format: %s_seq
tblname_format: %s
The following parameters can be customized under the param section:
| Key | Description | Default Value |
|---|---|---|
dsn |
The PDO DSN (required) | - |
username |
The database username | - |
password |
The database password | - |
encoding |
The default charset | utf8 |
attributes |
A set of Doctrine attributes | - |
The following attributes can be customized under the attributes section:
| Key | Description | Default Value |
|---|---|---|
quote_identifier |
Whether to wrap identifiers with quotes | false |
use_native_enum |
Whether to use native enums | false |
validate |
Whether to enable data validation | true |
idxname_format |
Format for index names | %s_idx |
seqname_format |
Format for sequence names | %s_seq |
tblname_format |
Format for table names | %s |
If you find a typo or an error, please register and open a ticket.
If you need support or have a technical question, please post to the official user mailing-list.