In this article we assume that you are familiar with The YAML Format and Configuration File Principles.
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. Doctrine 1.2
env_name: conn_name: class: sfDoctrineDatabase file: absolute_path_to_class_file param: dsn: dsn_string username: user_name password: user_password encoding: charset profiler: <true | false> logging: <true | false> attributes: quote_identifier: <true | false> use_native_enum: <true | false> use_native_set: <true | false> use_dql_callbacks: <true | false> decimal_places: default_column_scale idxname_format: index_name_mask seqname_format: sequence_name_mask tblname_format: table_name_mask default_table_type: <INNODB | MyISAM> default_table_collate: collation_name default_table_charset: charset_name export: <all | tables | none> emulate_database: <true | false> autoload_table_classes: <true | false> throw_exceptions: <true | false> auto_free_query_objects: <true | false> hydrate_overwrite: <true | false> cascade_saves: <true | false> query_class: class_name collection_class: class_name table_class: class_name default_identifier_options: name: id_name type: id_type length: id_length autoincrement: <true | false> primary: <true | false> default_column_options: option: value
The databases.yml file is environment-aware, therefore you can add configurations for different environments by specifying environment name (eg.: prod, test) or 'all' for all environments.
Connection name eg.: doctrine
PHP class used to create database connection instance. Must extend sfDatabase abstract class.
Possible values: sfDoctrineDatabase
Absolute path to the PHP class file which is represented in the class attribute
A set of Doctrine connection parameters. These parameters are passed as an array to the constructor of the sfDatabase class instance.
Defines data source name (DSN). Doctrine supports both PEAR DB/MDB2 and PDO style data source names. PEAR MDB2 style syntax:
driver://username:password@host/database_name
PDO style syntax:
driver:host=localhost;dbname=database_name
The currently supported PDO database drivers are:
User name used to connect to database.
Password used to connect to database.
The default charset.
Default: UTF8
Indicates whether to output doctrine log to the debug toolbar. The default value of profiler depends on the environment. In development environment the default value is true, otherwise - false.
Possible values: <true | false>
Default: sfConfig::get('sf_debug')
Specifies whether to enable logging. This option takes effect only when profiler is set to true.
Possible values: <true | false>
This parameter specifies the array of attributes for connection.
Specifies whether to wrap identifiers with quotes. When this attribute is set to true all of the field identifiers will be automatically quoted in the resulting SQL statements.
Possible values: <true | false>
If you wish to use native enum types for your DBMS if it supports it, then you must set this attribute to true.
Currently only mysql driver supports this.
Possible values: <true | false> Default: false
If you wish to use native set types for your DBMS if it supports it, then you must set this attribute to true. Currently only mysql driver supports this. Possible values: <true | false> Default: false
Specifies whether to enable or disable DQL callbacks. Possible values: <true | false> Default: false
An integer value which specifies the default scale for the columns of type float, double or decimal. Default: 2
Specifies the format for index names. This option can be used for changing the naming convention of indexes. By default Doctrine uses the format [name]_idx. So defining an index called productindex will actually be converted into productindex_idx. Default: %s_idx
Specifies the format for sequence names. This option can be used for changing the naming convention of sequences. By default Doctrine uses the format [name]_seq, hence creating a new sequence with the name of mysequence will lead into creation of sequence called mysequence_seq. Default: %s_seq
Specifies the format for table names. This option can be used for changing the naming convention of tables. Default: %s
Determines the default type of the table engine will be used in the database for the tables. Use this attribute for MySQL database. Possible values: <INNODB | MyISAM>
Specifies the default collation for the tables (eg. utf8_unicode_ci).
Specifies the default character set for the tables (eg. utf8).
Specifies what Doctrine should export when exporting classes to your database for creating your tables. Available values:
Possible values: <all | tables | none> Default: all
Specifies whether or not to emulate databases for Oracle. Possible values: <true | false>
Specifies whether or not to load custom Doctrine_Table classes. Possible values: <true | false> Default: true
Specifies whether to throw exceptions when error occurs on Doctrine query execution. Possible values: <true | false> Default: true
Specifies whether to auto free query objects after execution. Possible values: <true | false> Default: false
Doctrine uses an identity map internally to make sure that multiple objects for one record in a database don't ever exist. If you fetch an object and modify some of its properties, then re-fetch that same object later, the modified properties will be overwritten by default. You can change this behavior by changing the hydrate_overwrite attribute to false. Possible values: <true | false> Default: true
Specifies whether or not to disable the cascading save operations which are enabled by default for convenience. If you set this attribute to false it will only cascade and save if the record is dirty. This means that you can't cascade and save records who are dirty that are more than one level deep in the hierarchy, but you benefit with a significant performance improvement. Possible values: <true | false> Default: true
Specifies which query class Doctrine should return whenever you instantiate a new query. The only requirement is that it extends the Doctrine_Query class. Default: Doctrine_Query
Specifies which collection class Doctrine should use whenever a new collection is instantiated. The only requirement is that it must extend Doctrine_Collection. Default: Doctrine_Collection
Specifies the class to be returned when using the Doctrine_Core::getTable() method. The only requirement is that the class extends Doctrine_Table. This attribute takes effect when autoload_table_classes is set to false. Default: Doctrine_Table
Specifies the properties of the automatically added primary key in Doctrine models. Symfony automaticaly generates primary key only if there is no explicitly specified one in the database table schema.
Specifies the name of the identifier column. Default: id
Specifies the data type of the identifier column, Default: integer
An integer value that specifies the length of identifier column. Default: 8
Specifies whether an identifier column is a special identity column in the database that generates a value on insertion of a row. Possible values: <true | false> Default: true
Specifies whether the identifier column is a primary key. Possible values: <true | false> Default: true
Specifies an array of default column options to be used on every column in your model.
Here you can define any option from the columns section of shema.yml file. For example if you want to define a default scale and make all columns not null, then add scale and notnull options:
all: doctrine: ... param: ... attributes: default_column_options: scale: 8 notnull: true