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.
60 lines
1.8 KiB
Plaintext
60 lines
1.8 KiB
Plaintext
++++ Introduction
|
|
|
|
{{Doctrine_Manager}} is the heart of every Doctrine based application. {{Doctrine_Manager}} handles all connections (database connections).
|
|
|
|
|
|
++++ Opening a new connection
|
|
|
|
In order to get your first application started you first need to get an instance of Doctrine_Manager which handles all the connections (database connections). The second thing to do is to open a new connection.
|
|
|
|
<code type="php">
|
|
// Doctrine_Manager controls all the connections
|
|
|
|
$manager = Doctrine_Manager::getInstance();
|
|
|
|
// Doctrine_Connection
|
|
// a script may have multiple open connections
|
|
// (= multiple database connections)
|
|
$dbh = new PDO('dsn','username','password');
|
|
$conn = $manager->openConnection();
|
|
|
|
// or if you want to use Doctrine Doctrine_Db and its
|
|
// performance monitoring capabilities
|
|
|
|
$dsn = 'schema://username:password@dsn/dbname';
|
|
$dbh = Doctrine_Db::getConnection($dsn);
|
|
$conn = $manager->openConnection();
|
|
</code>
|
|
|
|
|
|
++++ Managing connections
|
|
|
|
Switching between connections in Doctrine is very easy, you just call {{Doctrine_Manager::setCurrentConnection()}} method. You can access the connection by calling {{Doctrine_Manager::getConnection()}} or {{Doctrine_Manager::getCurrentConnection()}} if you only want to get the current connection.
|
|
|
|
<code type="php">
|
|
// Doctrine_Manager controls all the connections
|
|
|
|
$manager = Doctrine_Manager::getInstance();
|
|
|
|
// open first connection
|
|
|
|
$conn = $manager->openConnection(new PDO('dsn','username','password'), 'connection 1');
|
|
|
|
// open second connection
|
|
|
|
$conn2 = $manager->openConnection(new PDO('dsn2','username2','password2'), 'connection 2');
|
|
|
|
$manager->getCurrentConnection(); // $conn2
|
|
|
|
$manager->setCurrentConnection('connection 1');
|
|
|
|
$manager->getCurrentConnection(); // $conn
|
|
|
|
// iterating through connections
|
|
|
|
foreach($manager as $conn) {
|
|
|
|
}
|
|
</code>
|
|
|