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.

uild and execute the following SQL:<br />

// UPDATE `tbl_user` SET `name`=:name WHERE id=:id<br />

$command->update('tbl_user', array(<br />

'name'=>'Tester',<br />

), 'id=:id', array(':id'=>1));<br />

delete<br />

function delete($table, $conditions='', $params=array())<br />

The delete method builds and executes a DELETE SQL statement. The $table parameter<br />

specifies which table to be updated; $conditions and $params are like in where, which<br />

specify the WHERE clause in theDELETE statement. The method will quote the table<br />

name properly.<br />

Below is an example:<br />

// build and execute the following SQL:<br />

// DELETE FROM `tbl_user` WHERE id=:id<br />

$command->delete('tbl_user', 'id=:id', array(':id'=>1));<br />

Building Schema Manipulation Queries<br />

Besides normal data retrieval and manipulation queries, the query builder also offers a set<br />

of methods for building and executing SQL queries that can manipulate the schema of a<br />

database. In particular, it supports the following queries:<br />

• createTable: creates a table<br />

• renameTable: renames a table<br />

• dropTable: drops a table<br />

• truncateTable: truncates a table<br />

• addColumn: adds a table column<br />

• renameColumn: renames a table column<br />

• alterColumn: alters a table column<br />

• dropColumn: drops a table column<br />

• createIndex: creates an index<br />

• dropIndex: drops an index<br />

Info: Although the actual SQL statements for manipulating database schema vary<br />

widely across different DBMS, the query builder attempts to provide a uniform interface<br />

for building these queries. This simplifies the task of migrating a database from one<br />

DBMS to another.<br />

Abstract Data Types<br />

The query builder introduces a set of abstract data types that can be used in defining table<br />

columns. Unlike the physical data types that are specific to particular DBMS and are quite

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

Saved successfully!

Ooh no, something went wrong!