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.
function having($conditions, $params=array())<br />
The having method specifies the HAVING part of a query. Its usage is the same as where.<br />
Below are some examples:<br />
// HAVING id=1 or id=2<br />
having('id=1 or id=2')<br />
// HAVING id=1 OR id=2<br />
having(array('or', 'id=1', 'id=2'))<br />
union<br />
function union($sql)<br />
The union method specifies the UNION part of a query. It appends $sql to the existing<br />
SQL using UNION operator. Calling union() multiple times will append multiple SQLs to the<br />
existing SQL.<br />
Below are some examples:<br />
// UNION (select * from tbl_profile)<br />
union('select * from tbl_profile')<br />
Executing Queries<br />
After calling the above query builder methods to build a query, we can call the DAO<br />
methods as described in Data Access Objects to execute the query. For example, we can<br />
call CDbCommand::queryRow() to obtain a row of result, or CDbCommand::queryAll() to<br />
get all rows at once. Example:<br />
$users = <strong>Yii</strong>::app()->db->createCommand()<br />
->select('*')<br />
->from('tbl_user')<br />
->queryAll();<br />
Retrieving SQLs<br />
Besides executing a query built by the Query Builder, we can also retrieve the<br />
corresponding SQL statement. This can be <strong>do</strong>ne by calling CDbCommand::getText().