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) 139<br />

WHERE u.id IN (?,<br />

?,<br />

?,<br />

?)<br />

Like Expressions<br />

Syntax:<br />

string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]<br />

Listing<br />

9-83<br />

The string_expression must have a string value. The pattern_value is a string literal or a<br />

string-valued input parameter in which an underscore (_) stands for any single character, a<br />

perc<strong>en</strong>t (%) character stands for any sequ<strong>en</strong>ce of characters (including the empty sequ<strong>en</strong>ce),<br />

and all other characters stand for themselves. The optional escape_character is a singlecharacter<br />

string literal or a character-valued input parameter (i.e., char or Character) and is<br />

used to escape the special meaning of the underscore and perc<strong>en</strong>t characters in<br />

pattern_value.<br />

Examples:<br />

• address.phone LIKE '12%3' is true for '123' '12993' and false for '1234'<br />

• as<strong>en</strong>t<strong>en</strong>ce.word LIKE 'l_se' is true for 'lose' and false for 'loose'<br />

• aword.underscored LIKE '\_%' ESCAPE '\' is true for '_foo' and false for 'bar'<br />

• address.phone NOT LIKE '12%3' is false for '123' and '12993' and true for '1234'<br />

If the value of the string_expression or pattern_value is NULL or unknown, the value of the<br />

LIKE expression is unknown. If the escape_characteris specified and is NULL, the value of the<br />

LIKE expression is unknown.<br />

Find all users whose email <strong>en</strong>ds with '@gmail.com':<br />

// test.php<br />

Listing<br />

9-84<br />

// ...<br />

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

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

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

->leftJoin('u.Email e')<br />

->where('e.address LIKE ?', '%@gmail.com');<br />

echo $q->getSqlQuery();<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 />

LEFT JOIN email e ON u.id = e.user_id<br />

WHERE e.address LIKE ?<br />

Listing<br />

9-85<br />

Find all users whose name starts with letter 'A':<br />

// test.php<br />

Listing<br />

9-86<br />

// ...<br />

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

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

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

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

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

Saved successfully!

Ooh no, something went wrong!