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 9: DQL (<strong>Doctrine</strong> Query Language) 134<br />

Listing<br />

9-59<br />

The above call to getSql() would output the following SQL query:<br />

SELECT<br />

u.id AS u__id<br />

FROM user u<br />

WHERE u.type = ?<br />

AND u.is_active = ?<br />

OR u.is_super_admin = ?<br />

Conditional expressions<br />

Literals<br />

Strings<br />

A string literal that includes a single quote is repres<strong>en</strong>ted by two single quotes; for example:<br />

´´literal´s´´.<br />

Listing<br />

9-60<br />

// test.php<br />

// ...<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->select('u.id, u.username')<br />

->from('User u')<br />

->where('u.username = ?', 'Vinc<strong>en</strong>t');<br />

echo $q->getSqlQuery();<br />

The above call to getSql() would output the following SQL query:<br />

Listing<br />

9-61<br />

SELECT<br />

u.id AS u__id,<br />

u.username AS u__username<br />

FROM user u<br />

WHERE u.username = ?<br />

Integers<br />

Because we passed the value of the username as a parameter to the where() method it is<br />

not included in the g<strong>en</strong>erated SQL. PDO handles the replacem<strong>en</strong>t wh<strong>en</strong> you execute the<br />

query. To check the parameters that exist on a <strong>Doctrine</strong>_Query instance you can use the<br />

getParams() method.<br />

Integer literals support the use of PHP integer literal syntax.<br />

Listing<br />

9-62<br />

// test.php<br />

// ...<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->select('a.id')<br />

->from('User u')<br />

->where('u.id = 4');<br />

echo $q->getSqlQuery();<br />

The above call to getSql() would output the following SQL query:<br />

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

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

Saved successfully!

Ooh no, something went wrong!