メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Pdo::createTable

Set create table query

Description​

public self Pdo::createTable( string $table, array $field )

Builds a Create Table. Tables are normally defined in site/config/database/*.yaml and created with ./fegg-cli migration.

Arguments​

NameData typeDefaultRemarks
$tablestringTable name
$fieldarrayList of column definitions (below)

Column definition​

Every key must be present.

KeyData typeRemarks
namestringColumn name
typestringColumn type
notnullbooleanAdd NOT NULL
dflt_valuemixedDefault value (null, '' or 0: no default)
pkbooleanAdd PRIMARY KEY
aibooleanAdd AUTOINCREMENT

Example​

Controller
$db = new \Fegg\Database\Pdo();

// Create Table "sample" (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title TEXT DEFAULT 'none')
$db->createTable('sample', array(
array('name' => 'id', 'type' => 'INTEGER', 'notnull' => true, 'dflt_value' => null, 'pk' => true, 'ai' => true),
array('name' => 'title', 'type' => 'TEXT', 'notnull' => false, 'dflt_value' => 'none', 'pk' => false, 'ai' => false),
))->execute();