Инструменты пользователя

Инструменты сайта


php:symfony:1x:yml:databases.yml

Содержание

Symfony YAML Configuration Reference

The databases.yml configuration file

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

Environment and connection

env_name

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.

env_name > conn_name

Connection name eg.: doctrine

Connection configuration

env_name > conn_name > class

PHP class used to create database connection instance. Must extend sfDatabase abstract class.

Possible values: sfDoctrineDatabase

env_name > conn_name > file

Absolute path to the PHP class file which is represented in the class attribute

Connection parameters

env_name > conn_name > param

A set of Doctrine connection parameters. These parameters are passed as an array to the constructor of the sfDatabase class instance.

env_name > conn_name > param > dsn

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:

  • mysql - MySQL
  • mysqli - MySQL (supports new authentication protocol) (requires PHP 5)
  • pgsql - PostgreSQL
  • mssql - Microsoft SQL Server (NOT for Sybase. Compile PHP –with-mssql)
  • oci - Oracle 7/8/9/10
  • sqlite - SQLite 2
  • ibase - InterBase / Firebird (requires PHP 5)
  • fbsql - FrontBase
  • querysim - QuerySim

env_name > conn_name > param > username

User name used to connect to database.

env_name > conn_name > param > password

Password used to connect to database.

env_name > conn_name > param > encoding

The default charset.

Default: UTF8

env_name > conn_name > param > profiler

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')

env_name > conn_name > param > logging

Specifies whether to enable logging. This option takes effect only when profiler is set to true.

Possible values: <true | false>

Connection attributes

env_name > conn_name > param > attributes

This parameter specifies the array of attributes for connection.

env_name > conn_name > param > attributes > quote_identifier

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>

env_name > conn_name > param > attributes > use_native_enum

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

env_name > conn_name > param > attributes > use_native_set

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

env_name > conn_name > param > attributes > use_dql_callbacks

Specifies whether to enable or disable DQL callbacks. Possible values: <true | false> Default: false

env_name > conn_name > param > attributes > decimal_places

An integer value which specifies the default scale for the columns of type float, double or decimal. Default: 2

env_name > conn_name > param > attributes > idxname_format

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

env_name > conn_name > param > attributes > seqname_format

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

env_name > conn_name > param > attributes > tblname_format

Specifies the format for table names. This option can be used for changing the naming convention of tables. Default: %s

env_name > conn_name > param > attributes > default_table_type

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>

env_name > conn_name > param > attributes > default_table_collate

Specifies the default collation for the tables (eg. utf8_unicode_ci).

env_name > conn_name > param > attributes > default_table_charset

Specifies the default character set for the tables (eg. utf8).

env_name > conn_name > param > attributes > export

Specifies what Doctrine should export when exporting classes to your database for creating your tables. Available values:

  • all - exports everything (tables and constraints);
  • tables - exporting tables only (but not constraints);
  • none - exports nothing. Use this value if you do not want the table to appear in the database.

Possible values: <all | tables | none> Default: all

env_name > conn_name > param > attributes > emulate_database

Specifies whether or not to emulate databases for Oracle. Possible values: <true | false>

env_name > conn_name > param > attributes > autoload_table_classes

Specifies whether or not to load custom Doctrine_Table classes. Possible values: <true | false> Default: true

env_name > conn_name > param > attributes > throw_exceptions

Specifies whether to throw exceptions when error occurs on Doctrine query execution. Possible values: <true | false> Default: true

env_name > conn_name > param > attributes > auto_free_query_objects

Specifies whether to auto free query objects after execution. Possible values: <true | false> Default: false

env_name > conn_name > param > attributes > hydrate_overwrite

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

env_name > conn_name > param > attributes > cascade_saves

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

env_name > conn_name > param > attributes > query_class

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

env_name > conn_name > param > attributes > collection_class

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

env_name > conn_name > param > attributes > table_class

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

Default identifier options

env_name > conn_name > param > attributes > default_identifier_options

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.

env_name > conn_name > param > attributes > default_identifier_options > name

Specifies the name of the identifier column. Default: id

env_name > conn_name > param > attributes > default_identifier_options > type

Specifies the data type of the identifier column, Default: integer

env_name > conn_name > param > attributes > default_identifier_options > length

An integer value that specifies the length of identifier column. Default: 8

env_name > conn_name > param > attributes > default_identifier_options > autoincrement

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

env_name > conn_name > param > attributes > default_identifier_options > primary

Specifies whether the identifier column is a primary key. Possible values: <true | false> Default: true

Default column options

env_name > conn_name > param > attributes > default_column_options

Specifies an array of default column options to be used on every column in your model.

env_name > conn_name > param > attributes > default_column_options > option

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
/var/www/source/data/pages/php/symfony/1x/yml/databases.yml.txt · Последнее изменение: 2024/02/05 12:40 (внешнее изменение)