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 10: Compon<strong>en</strong>t Overview 163<br />

Connection<br />

<strong>Doctrine</strong>_Connection is a wrapper for database connection. The connection is typically an<br />

instance of PDO but because of how <strong>Doctrine</strong> is designed, it is possible to design your own<br />

adapters that mimic the functionality that PDO provides.<br />

The <strong>Doctrine</strong>_Connection class handles several things:<br />

• Handles database portability things missing from PDO (eg. LIMIT / OFFSET<br />

emulation)<br />

• Keeps track of <strong>Doctrine</strong>_Table objects<br />

• Keeps track of records<br />

• Keeps track of records that need to be updated / inserted / deleted<br />

• Handles transactions and transaction nesting<br />

• Handles the actual querying of the database in the case of INSERT / UPDATE /<br />

DELETE operations<br />

• Can query the database using DQL. You will learn more about DQL in the DQL<br />

(<strong>Doctrine</strong> Query Language) (page 120) chapter.<br />

• Optionally validates transactions using <strong>Doctrine</strong>_Validator and gives full information<br />

of possible errors.<br />

Available Drivers<br />

<strong>Doctrine</strong> has drivers for every PDO-supported database. The supported databases are:<br />

• FreeTDS / Microsoft SQL Server / Sybase<br />

• Firebird/Interbase 6<br />

• Informix<br />

• Mysql<br />

• Oracle<br />

• Odbc<br />

• PostgreSQL<br />

• Sqlite<br />

Creating Connections<br />

// bootstrap.php<br />

Listing<br />

10-4<br />

// ...<br />

$conn = <strong>Doctrine</strong>_Manager::connection('mysql://username:password@localhost/<br />

test', 'connection 1');<br />

We have already created a new connection in the previous chapters. You can skip the<br />

above step and use the connection we've already created. You can retrieve it by using the<br />

<strong>Doctrine</strong>_Manager::connection() method.<br />

Flushing the Connection<br />

Wh<strong>en</strong> you create new User records you can flush the connection and save all un-saved<br />

objects for that connection. Below is an example:<br />

// test.php<br />

Listing<br />

10-5<br />

// ...<br />

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

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

Saved successfully!

Ooh no, something went wrong!