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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

different in different DBMS, the abstract data types are independent of DBMS. When<br />

abstract data types are used in defining table columns, the query builder will convert them<br />

into the corresponding physical data types.<br />

The following abstract data types are supported by the query builder.<br />

• pk: a generic primary key type, will be converted into int(11) NOT NULL<br />

AUTO_INCREMENT PRIMARY KEY for MySQL;<br />

• string: string type, will be converted into varchar(255) for MySQL;<br />

• text: text type (long string), will be converted into text for MySQL;<br />

• integer: integer type, will be converted into int(11) for MySQL;<br />

• float: floating number type, will be converted into float for MySQL;<br />

• decimal: decimal number type, will be converted into decimal for MySQL;<br />

• datetime: datetime type, will be converted into datetime for MySQL;<br />

• timestamp: timestamp type, will be converted into timestamp for MySQL;<br />

• time: time type, will be converted into time for MySQL;<br />

• date: date type, will be converted into date for MySQL;<br />

• binary: binary data type, will be converted into blob for MySQL;<br />

• boolean: boolean type, will be converted into tinyint(1) for MySQL.<br />

createTable<br />

function createTable($table, $columns, $options=null)<br />

The createTable method builds and executes a SQL statement for creating a table. The<br />

$table parameter specifies the name of the table to be created. The $columns parameter<br />

specifies the columns in the new table. They must be given as name-definition pairs (e.g.<br />

'username'=>'string'). The $options parameter specifies any extra SQL fragment that<br />

should be appended to the generated SQL. The query builder will quote the table name as<br />

well as the column names properly.<br />

When specifying a column definition, one can use an abstract data type as described<br />

above. The query builder will convert the abstract data type into the corresponding<br />

physical data type, according to the currently used DBMS. For example, string will be<br />

converted into varchar(255) for MySQL.<br />

A column definition can also contain non-abstract data type or specifications. They will be<br />

put in the generated SQL without any change. For example, point is not an abstract data<br />

type, and if used in a column definition, it will appear as is in the resulting SQL; and string<br />

NOT NULL will be converted into varchar(255) NOT NULL (i.e., only the abstract type<br />

string is converted).<br />

Below is an example showing how to create a table:

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

Saved successfully!

Ooh no, something went wrong!