O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Data manipulation queries refer to SQL statements for inserting, updating and deleting<br />
data in a DB table. Corresponding to these queries, the query builder provides insert,<br />
update and delete methods, respectively. Unlike the SELECT query methods described<br />
above, each of these data manipulation query methods will build a complete SQL<br />
statement and execute it immediately.<br />
• insert: inserts a row into a table<br />
• update: updates the data in a table<br />
• delete: deletes the data from a table<br />
Below we describe these data manipulation query methods.<br />
insert<br />
function insert($table, $columns)<br />
The insert method builds and executes an INSERT SQL statement. The $table parameter<br />
specifies which table to be inserted into, while $columns is an array of name-value pairs<br />
specifying the column values to be inserted. The method will quote the table name<br />
properly and will use parameter-binding for the values to be inserted.<br />
Below is an example:<br />
// build and execute the following SQL:<br />
// INSERT INTO `tbl_user` (`name`, `email`) VALUES (:name, :email)<br />
$command->insert('tbl_user', array(<br />
'name'=>'Tester',<br />
'email'=>'tester@example.com',<br />
));<br />
update<br />
function update($table, $columns, $conditions='', $params=array())<br />
The update method builds and executes an UPDATE SQL statement. The $table<br />
parameter specifies which table to be updated; $columns is an array of name-value pairs<br />
specifying the column values to be updated;$conditions and $params are like in where,<br />
which specify the WHERE clause in the UPDATE statement. The method will quote the<br />
table name properly and will use parameter-binding for the values to be updated.<br />
Below is an example: