Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
59e17b53
Commit
59e17b53
authored
Dec 04, 2014
by
David Zuelke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs :)
parent
f8a1c795
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
0 deletions
+90
-0
configuration.rst
docs/en/reference/configuration.rst
+90
-0
No files found.
docs/en/reference/configuration.rst
View file @
59e17b53
...
...
@@ -21,6 +21,18 @@ You can get a DBAL Connection through the
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
Or, using the simpler URL form:
.. code-block:: php
<?php
$config = new \Doctrine\DBAL\Configuration();
//..
$connectionParams = array(
'url' => 'mysql://user:secret@localhost/mydb',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
The ``DriverManager`` returns an instance of
``Doctrine\DBAL\Connection`` which is a wrapper around the
underlying driver connection (which is often a PDO instance).
...
...
@@ -28,6 +40,84 @@ underlying driver connection (which is often a PDO instance).
The following sections describe the available connection parameters
in detail.
Connecting using a URL
~~~~~~~~~~~~~~~~~~~~~~
The easiest way to specify commonly used connection parameters is
using a database URL. The scheme is used to specify a driver, the
user and password in the URL encode user and password for the
connection, followed by the host and port parts (the "authority").
The path after the authority part represents the name of the
database, sans the leading slash. Any query parameters are used as
additional connection parameters.
The scheme names representing the drivers are either the regular
driver names (see below) with any underscores in their name replaced
with a hyphen (to make them legal in URL scheme names), or one of the
following simplified driver names that serve as aliases:
- ``db2``: alias for ``ibm_db2``
- ``mssql``: alias for ``pdo_sqlsrv``
- ``mysql``/``mysql2``: alias for ``pdo_mysql``
- ``pgsql``/``postgres``/``postgresql``: alias for ``pdo_pgsql``
- ``sqlite``/``sqlite3``: alias for ``pdo_sqlite``
For example, to connect to a "foo" MySQL DB using the ``pdo_mysql``
driver on localhost port 4486 with the charset set to UTF-8, you
would use the following URL::
mysql://localhost:4486/foo?charset=UTF-8
This is identical to the following connection string using the
full driver name::
pdo-mysql://localhost:4486/foo?charset=UTF-8
If you wanted to use the ``drizzle_pdo__mysql`` driver instead::
drizzle-pdo-mysql://localhost:4486/foo?charset=UTF-8
In the two last example above, mind the dashes instead of the
underscores in the URL schemes.
For connecting to an SQLite database, the authority portion of the
URL is obviously irrelevant and thus can be omitted. The path part
of the URL is, like for all other drivers, stripped of its leading
slash, resulting in a relative file name for the database::
sqlite:///somedb.sqlite
This would access ``somedb.sqlite`` in the current working directory
and is identical to the following::
sqlite://ignored:ignored@ignored:1234/somedb.sqlite
To specify an absolute file path, e.g. ``/usr/local/var/db.sqlite``,
simply use that as the database name, which results in two leading
slashes for the path part of the URL, and four slashes in total after
the URL scheme name and its following colon::
sqlite:////usr/local/var/db.sqlite
Which is, again, identical to supplying ignored user/pass/authority::
sqlite://notused:inthis@case//usr/local/var/db.sqlite
To connect to an in-memory SQLite instance, use ``:memory::`` as the
database name::
sqlite:///:memory:
.. note::
Any information extracted from the URL overwrites existing values
for the parameter in question, but the rest of the information
is merged together. You could, for example, have a URL without
the ``charset`` setting in the query string, and then add a
``charset`` connection parameter next to ``url``, to provide a
default value in case the URL doesn't contain a charset value.
Driver
~~~~~~
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment