Skip to content

Dbal configuration #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 73 additions & 16 deletions guides/doctrine/dbal/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
Configuration
=============

One example configuration with a MySQL database could look like this following
example:

.. code-block:: yaml

# app/config/config.yml
Expand All @@ -14,26 +17,74 @@ Configuration
user: root
password: null

You can also specify some additional configurations on a connection but they
are not required:
The DoctrineBundle supports all parameters that all the default doctrine drivers
accept, converted to the XML or YAML naming standards that Symfony enforces.
See the Doctrine DBAL `documentation`_ for more information. Additionally
there are some Symfony related options that you can configure. The following
block shows all possible configuration keys without explaining their meaning
further:

.. code-block:: yaml
.. configuration-block::

# ...
.. code-block:: yaml

doctrine.dbal:
# ...
doctrine.dbal:
dbname: database
host: localhost
port: 1234
user: user
password: secret
driver: pdo_mysql
driver_class: MyNamespace\MyDriverImpl
options:
foo: bar
path: %kernel.data_dir%/data.sqlite
memory: true
unix_socket: /tmp/mysql.sock
wrapper_class: MyDoctrineDbalConnectionWrapper
charset: UTF-8
logging: %kernel.debug%
platform_service: MyOwnDatabasePlatformService

.. code-block:: xml

<!-- xmlns:doctrine="http://www.symfony-project.org/schema/dic/doctrine" -->
<!-- xsi:schemaLocation="http://www.symfony-project.org/schema/dic/doctrine http://www.symfony-project.org/schema/dic/doctrine/doctrine-1.0.xsd"> -->

<doctrine:dbal
dbname="database"
host="localhost"
port="1234"
user="user"
password="secret"
driver="pdo_mysql"
driver-class="MyNamespace\MyDriverImpl"
path="%kernel.data_dir%/data.sqlite"
memory="true"
unix-socket="/tmp/mysql.sock"
wrapper-class="MyDoctrineDbalConnectionWrapper"
charset="UTF-8"
logging="%kernel.debug%"
platform-service="MyOwnDatabasePlatformService"
/>

host: localhost
port: ~
path: %kernel.data_dir%/symfony.sqlite
event_manager_class: Doctrine\Common\EventManager
configuration_class: Doctrine\DBAL\Configuration
wrapper_class: ~
options: []
There are also a bunch of dependency injection container parameters
that allow you to specify which classes are used (with their default values):

.. code-block:: yaml

parameters:
doctrine.dbal.logger_class: Symfony\Bundle\DoctrineBundle\Logger\DbalLogger
doctrine.dbal.configuration_class: Doctrine\DBAL\Configuration
doctrine.data_collector.class: Symfony\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector
doctrine.dbal.event_manager_class: Doctrine\Common\EventManager
doctrine.dbal.events.mysql_session_init.class: Doctrine\DBAL\Event\Listeners\MysqlSessionInit
doctrine.dbal.events.oracle_session_init.class: Doctrine\DBAL\Event\Listeners\OracleSessionInit
doctrine.dbal.logging: false

If you want to configure multiple connections you can do so by simply listing
them under the key named ``connections``:
them under the key named ``connections``. All the parameters shown above
can also be specified in the connections subkeys.

.. code-block:: yaml

Expand All @@ -60,6 +111,12 @@ connection name that you want get::
{
public function indexAction()
{
$conn = $this->get('doctrine.dbal.customer_connection');
$defaultConn1 = $this->get('doctrine.dbal.connection');
$defaultConn2 = $this->get('doctrine.dbal.default_connection');
// $defaultConn1 === $defaultConn2

$customerConn = $this->get('doctrine.dbal.customer_connection');
}
}
}

.. _documentation: http://www.doctrine-project.org/projects/dbal/2.0/docs/en
4 changes: 2 additions & 2 deletions guides/doctrine/orm/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ compatible field that handles arrays of values::
'em' => $em,
'className' => 'Product',
));

$field = new ChoiceField('products', array(
'choices' => $productChoices,
'multiple' => true,
Expand Down Expand Up @@ -79,4 +79,4 @@ be chosen from::
));

$form->add($engineerField);
$form->add($reporterField);
$form->add($reporterField);