5329c3827c
* Fixed a few layout bugs in new documentation * Fixed documentation table of contents indentation bug in IE6 (fixes #344) * Fixed a parser bug in Sensei_Doc_Section * Restructrured a bit some files of the documentation.
34 lines
929 B
Plaintext
34 lines
929 B
Plaintext
Opening a new database connection in Doctrine is very easy. If you wish to use PDO (www.php.net/PDO) you can just initalize a new PDO object:
|
|
|
|
<code type="php">
|
|
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
|
|
$user = 'dbuser';
|
|
$password = 'dbpass';
|
|
|
|
try {
|
|
$dbh = new PDO($dsn, $user, $password);
|
|
} catch (PDOException $e) {
|
|
echo 'Connection failed: ' . $e->getMessage();
|
|
}
|
|
</code>
|
|
|
|
If your database extension isn't supported by PDO you can use special {{Doctrine_Adapter}} class (if availible). The following example uses db2 adapter:
|
|
|
|
<code type="php">
|
|
$dsn = 'db2:dbname=testdb;host=127.0.0.1';
|
|
$user = 'dbuser';
|
|
$password = 'dbpass';
|
|
|
|
try {
|
|
$dbh = Doctrine_Adapter::connect($dsn, $user, $password);
|
|
} catch (PDOException $e) {
|
|
echo 'Connection failed: ' . $e->getMessage();
|
|
}
|
|
</code>
|
|
|
|
The next step is opening a new {{Doctrine_Connection}}.
|
|
|
|
<code type="php">
|
|
$conn = Doctrine_Manager::connection($dbh);
|
|
</code>
|