20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SELECT DISTINCT `id`, `username`<br />

from<br />

function from($tables)<br />

The from method specifies the FROM part of a query. The $tables parameter specifies<br />

which tables to be selected from. This can be either a string representing commaseparated<br />

table names, or an array of table names. Table names can contain schema<br />

prefixes (e.g. public.tbl_user) and/or table aliases (e.g. tbl_user u). The method will<br />

automatically quote the table names unless it contains some parenthesis (which means<br />

the table is given as a sub-query or DB expression).<br />

Below are some examples:<br />

// FROM `tbl_user`<br />

from('tbl_user')<br />

// FROM `tbl_user` `u`, `public`.`tbl_profile` `p`<br />

from('tbl_user u, public.tbl_profile p')<br />

// FROM `tbl_user`, `tbl_profile`<br />

from(array('tbl_user', 'tbl_profile'))<br />

// FROM `tbl_user`, (select * from tbl_profile) p<br />

from(array('tbl_user', '(select * from tbl_profile) p'))<br />

where<br />

function where($conditions, $params=array())<br />

The where method specifies the WHERE part of a query. The $conditions parameter<br />

specifies query conditions while $params specifies the parameters to be bound to the<br />

whole query. The $conditions parameter can be either a string (e.g. id=1) or an array of the<br />

format:<br />

array(operator, operand1, operand2, ...)<br />

where operator can be any of the following:<br />

• and: the operands should be concatenated together using AND. For example, array<br />

('and', 'id=1', 'id=2') will generate id=1 AND id=2. If an operand is an array, it will be<br />

converted into a string using the same rules described here. For example, array('and',<br />

'type=1', array('or', 'id=1', 'id=2')) will generate type=1 AND (id=1 OR id=2). The<br />

method will NOT <strong>do</strong> any quoting or escaping.<br />

• or: similar as the and operator except that the operands are concatenated using OR.<br />

• in: operand 1 should be a column or DB expression, and operand 2 be an array<br />

representing the range of the values that the column or DB expression should be in.

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

Saved successfully!

Ooh no, something went wrong!