The symfony Reference Book

The databases.yml Configuration File

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "The symfony Reference Book" which is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License license.

Master symfony

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com

Chapter Content

Propel

Doctrine

symfony training
Be trained by symfony experts
Feb 21: Köln (Getting Started with Symfony2 - English)
Feb 27: Köln (Mastering Symfony2 - English)
Mar 05: Köln (Web Development with Symfony2 - Deutsch)
Mar 05: Montreal (Web Development with Symfony2 - English)
Mar 05: Montreal (Getting Started with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The symfony Reference Book" in English for the 1.2 version - Switch to version: - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.
The symfony reference guide
Support symfony!
Buy this book
or donate.
Buy The symfony reference guide from amazon.com

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 a databases.yml configuration 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.yml configuration file is cached as a PHP file; the process is automatically managed by the sfDatabaseConfigHandler class.

The database configuration can also be configured by using the database:configure task. This task updates the databases.yml according to the arguments you pass to it.

Propel

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 -

Doctrine

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
The security.yml Configuration File »
« The generator.yml Configuration File

Questions & Feedback

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.