1
0
mirror of synced 2024-12-15 07:36:03 +03:00
doctrine2/manual/new/docs/en/working-with-objects/component-overview/manager.txt
jepso 5329c3827c * Converted most of the docs to the new format.
* 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.
2007-06-13 21:30:32 +00:00

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>