1
0
mirror of synced 2024-12-15 07:36:03 +03:00
doctrine2/manual/new/docs/en/connection-management/dsn-the-data-source-name.txt
jepso 9b61957154 - New feature in documentation: you can now link to other documentation sections with the following syntax:
- [doc getting-started:installation], or
    - [doc getting-started:installation Custom link text]
- Updated Text_Wiki to 1.2.0
- Documentation should now pass XHTML validator
- Formatted DSN section so that it's easier on eyes
- The single quotes in <code type='php'> won't work anymore due to the Text_Wiki update. Use double quotes instead: <code type="php">. The single quotes have been converted to double quotes in documentation files.
- Modified the links in h1-h6 headings to use the same style as the headings.
- Some refactoring
2007-07-20 08:03:04 +00:00

112 lines
3.7 KiB
Plaintext

In order to connect to a database through Doctrine, you have to create a valid DSN - data source name.
Doctrine supports both PEAR DB/MDB2 like data source names as well as PDO style data source names. The following section deals with PEAR like data source names. If you need more info about the PDO-style data source names see [[php PDO->__construct()]].
The DSN consists in the following parts:
||~ DSN part ||~ Description ||
|| phptype || Database backend used in PHP (i.e. mysql , pgsql etc.) ||
|| dbsyntax || Database used with regards to SQL syntax etc. ||
|| protocol || Communication protocol to use ( i.e. tcp, unix etc.) ||
|| hostspec || Host specification (hostname[:port]) ||
|| database || Database to use on the DBMS server ||
|| username || User name for login ||
|| password || Password for login ||
|| proto_opts || Maybe used with protocol ||
|| option || Additional connection options in URI query string format. Options are separated by ampersand (&). The Following table shows a non complete list of options: ||
**List of options**
||~ Name ||~ Description ||
|| charset || Some backends support setting the client charset.||
|| new_link || Some RDBMS do not create new connections when connecting to the same host multiple times. This option will attempt to force a new connection. ||
The DSN can either be provided as an associative array or as a string. The string format of the supplied DSN is in its fullest form:
<code>phptype(dbsyntax)://username:password@protocol+hostspec/database?option=value</code>
Most variations are allowed:
<code>
phptype://username:password@protocol+hostspec:110//usr/db_file.db
phptype://username:password@hostspec/database
phptype://username:password@hostspec
phptype://username@hostspec
phptype://hostspec/database
phptype://hostspec
phptype:///database
phptype:///database?option=value&anotheroption=anothervalue
phptype(dbsyntax)
phptype
</code>
The currently supported database backends are:
||~ Driver name ||~ Supported databases ||
|| fbsql || FrontBase ||
|| ibase || InterBase / Firebird (requires PHP 5) ||
|| mssql || Microsoft SQL Server (NOT for Sybase. Compile PHP --with-mssql) ||
|| mysql || MySQL ||
|| mysqli || MySQL (supports new authentication protocol) (requires PHP 5) ||
|| oci8 || Oracle 7/8/9/10 ||
|| pgsql || PostgreSQL ||
|| querysim || QuerySim ||
|| sqlite || SQLite 2 ||
A second DSN format supported is
<code>
phptype(syntax)://user:pass@protocol(proto_opts)/database
</code>
If your database, option values, username or password contain characters used to delineate DSN parts, you can escape them via URI hex encodings:
||~ Character ||~ Hex Code ||
|| : || %3a ||
|| / || %2f ||
|| @ || %40 ||
|| + || %2b ||
|| ( || %28 ||
|| ) || %29 ||
|| ? || %3f ||
|| = || %3d ||
|| & || %26 ||
Warning
Please note, that some features may be not supported by all database backends.
+++ Examples
**Example 1.** Connect to database through a socket
<code>
mysql://user@unix(/path/to/socket)/pear
</code>
**Example 2.** Connect to database on a non standard port
<code>
pgsql://user:pass@tcp(localhost:5555)/pear
</code>
**Example 3.** Connect to SQLite on a Unix machine using options
<code>
sqlite:////full/unix/path/to/file.db?mode=0666
</code>
**Example 4.** Connect to SQLite on a Windows machine using options
<code>
sqlite:///c:/full/windows/path/to/file.db?mode=0666
</code>
**Example 5.** Connect to MySQLi using SSL
<code>
mysqli://user:pass@localhost/pear?key=client-key.pem&cert=client-cert.pem
</code>