10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: Configuration 33<br />

backtick ` MySQL<br />

double quote "<br />

Oracle<br />

brackets [ or ] Access<br />

Delimited id<strong>en</strong>tifiers are known to g<strong>en</strong>erally work correctly under the following drivers:<br />

Mssql, Mysql, Oracle, Pgsql, Sqlite and Firebird.<br />

Wh<strong>en</strong> using the <strong>Doctrine</strong>_Core::ATTR_QUOTE_IDENTIFIER option, all of the field<br />

id<strong>en</strong>tifiers will be automatically quoted in the resulting SQL statem<strong>en</strong>ts:<br />

// bootstrap.php<br />

Listing<br />

4-6<br />

// ...<br />

$conn->setAttribute(<strong>Doctrine</strong>_Core::ATTR_QUOTE_IDENTIFIER, true);<br />

Will result in a SQL statem<strong>en</strong>t that all the field names are quoted with the backtick '`'<br />

operator (in MySQL).<br />

SELECT<br />

*<br />

FROM sometable<br />

WHERE `id` = '123'<br />

Listing<br />

4-7<br />

As opposed to:<br />

SELECT<br />

*<br />

FROM sometable<br />

WHERE id = '123'<br />

Listing<br />

4-8<br />

Hydration Overwriting<br />

By default <strong>Doctrine</strong> is configured to overwrite any local changes you have on your objects if<br />

you were to query for some objects which have already be<strong>en</strong> queried for and modified.<br />

$user = <strong>Doctrine</strong>_Core::getTable('User')->find(1);<br />

$user->username = 'newusername';<br />

Listing<br />

4-9<br />

Now I have modified the above object and if I were to query for the same data again, my local<br />

changes would be overwritt<strong>en</strong>.<br />

$user = <strong>Doctrine</strong>_Core::getTable('User')->find(1);<br />

echo $user->username; // would output original username in database<br />

Listing<br />

4-10<br />

You can disable this behavior by using the ATTR_HYDRATE_OVERWRITE attribute:<br />

// bootstrap.php<br />

Listing<br />

4-11<br />

// ...<br />

$conn->setAttribute(<strong>Doctrine</strong>_Core::ATTR_HYDRATE_OVERWRITE, false);<br />

Now if were to run the same test we ran above, the modified username would not be<br />

overwritt<strong>en</strong>.<br />

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

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

Saved successfully!

Ooh no, something went wrong!