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
May 29: Paris (Web Development with Symfony2 - Français)
May 31: Paris (Mastering Symfony2 - Français)
Jun 06: Paris (Introduction to Symfony2 - Français)
Jun 06: Paris (Introduction to Symfony2 - English)
Jun 06: Paris (Going Further with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The symfony Reference Book" in English for the 1.4 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.
The symfony reference guide
Support symfony!
Buy this book
or donate.
Buy The symfony reference guide from amazon.com
You have been redirected to the symfony 1.4 documentation.
Both symfony 1.3 and symfony 1.4 share the same feature set and documentation.
Read about why we have two different versions.

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
      debug:
        realmemoryusage: true
        details:
          time:       { enabled: true }
          slow:       { enabled: true, threshold: 0.1 }
          mem:        { enabled: true }
          mempeak:    { enabled: true }
          memdelta:   { enabled: true }
 
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 -
debug Options for the DebugPDO class n/a

The debug entry defines all the options described in the Propel documentation. The following YAML shows all the available options:

debug:
  realmemoryusage: true
  details:
    time:
      enabled: true
    slow:
      enabled: true
      threshold: 0.001
    memdelta:
      enabled: true
    mempeak:
      enabled: true
    method:
      enabled: true
    mem:
      enabled: true
    querycount:
      enabled: true

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 false
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.