10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5: Connections 41<br />

$conn = <strong>Doctrine</strong>_Manager::connection();<br />

$name = $manager->getConnectionName($conn);<br />

echo $name; // connection 1<br />

Close Connection<br />

You can easily close a connection and remove it from the <strong>Doctrine</strong> connection registry with<br />

the following code:<br />

// test.php<br />

Listing<br />

5-7<br />

// ...<br />

$conn = <strong>Doctrine</strong>_Manager::connection();<br />

$manager->closeConnection($conn);<br />

If you wish to close the connection but not remove it from the <strong>Doctrine</strong> connection registry<br />

you can use the following code instead:<br />

// test.php<br />

Listing<br />

5-8<br />

// ...<br />

$conn = <strong>Doctrine</strong>_Manager::connection();<br />

$conn->close();<br />

Get All Connections<br />

You can retrieve an array of all the registered connections by using the<br />

<strong>Doctrine</strong>_Manager::getConnections() method like below:<br />

// test.php<br />

Listing<br />

5-9<br />

// ...<br />

$conns = $manager->getConnections();<br />

foreach ($conns as $conn) {<br />

echo $conn->getName() . "\n";<br />

}<br />

The above is ess<strong>en</strong>tially the same as iterating over the <strong>Doctrine</strong>_Manager object like we did<br />

earlier. Here it is again:<br />

// test.php<br />

Listing<br />

5-10<br />

// ...<br />

foreach ($manager as $conn) {<br />

echo $conn->getName() . "\n";<br />

}<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!