O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
• where: specifies the WHERE part of the query<br />
• join: appends an inner join query fragment<br />
• leftJoin: appends a left outer join query fragment<br />
• rightJoin: appends a right outer join query fragment<br />
• crossJoin: appends a cross join query fragment<br />
• naturalJoin: appends a natural join query fragment<br />
• group: specifies the GROUP BY part of the query<br />
• having: specifies the HAVING part of the query<br />
• order: specifies the ORDER BY part of the query<br />
• limit: specifies the LIMIT part of the query<br />
• offset: specifies the OFFSET part of the query<br />
• union: appends a UNION query fragment<br />
In the following, we explain how to use these query builder methods. For simplicity, we<br />
assume the underlying database is MySQL. Note that if you are using other DBMS, the<br />
table/column/value quoting shown in the examples may be different.<br />
select<br />
function select($columns='*')<br />
The select method specifies the SELECT part of a query. The $columns parameter<br />
specifies the columns to be selected, which can be either a string representing commaseparated<br />
columns, or an array of column names. Column names can contain table<br />
prefixes and/or column aliases. The method will automatically quote the column names<br />
unless a column contains some parenthesis (which means the column is given as a DB<br />
expression).<br />
Below are some examples:<br />
// SELECT *<br />
select()<br />
// SELECT `id`, `username`<br />
select('id, username')<br />
// SELECT `tbl_user`.`id`, `username` AS `name`<br />
select('tbl_user.id, username as name')<br />
// SELECT `id`, `username`<br />
select(array('id', 'username'))<br />
// SELECT `id`, count(*) as num<br />
select(array('id', 'count(*) as num'))<br />
selectDistinct<br />
function selectDistinct($columns)<br />
The selectDistinct method is similar as select except that it turns on the DISTINCT flag.<br />
For example,selectDistinct('id, username') will generate the following SQL: