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

Listing<br />

9-69<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 = 'admin'<br />

Predefined reserved literals are case ins<strong>en</strong>sitive, although its a good standard to write them<br />

in uppercase.<br />

Input parameters<br />

Here are some examples of using positional parameters:<br />

Single positional parameter:<br />

Listing<br />

9-70<br />

// test.php<br />

// ...<br />

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

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

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

->where('u.username = ?', array('Arnold'));<br />

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

Wh<strong>en</strong> the passed parameter for a positional parameter contains only one value you can<br />

simply pass a single scalar value instead of an array containing one value.<br />

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

Listing<br />

9-71<br />

SELECT<br />

u.id AS u__id<br />

FROM user u<br />

WHERE u.username = ?<br />

Multiple positional parameters:<br />

Listing<br />

9-72<br />

// test.php<br />

// ...<br />

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

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

->where('u.id > ? AND u.username LIKE ?', array(50, 'A%'));<br />

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

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

Listing<br />

9-73<br />

SELECT<br />

u.id AS u__id<br />

FROM user u<br />

WHERE (u.id > ?<br />

AND u.username LIKE ?)<br />

Here are some examples of using named parameters:<br />

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

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

Saved successfully!

Ooh no, something went wrong!