メインコンテンツまでスキップ
Version: Fegg 5.x

Pdo::createTable

CREATE TABLEのクエリを組み立てます

説明​

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

Create Tableを組み立てます。テーブルは通常、site/config/database/*.yamlで定義し、./fegg-cli migrationで作成します。

引数​

名前データ型デフォルト備考
$tablestringテーブル名
$fieldarrayカラムの定義の一覧(下記)

カラムの定義​

すべてのキーを指定します。

キーデータ型備考
namestringカラム名
typestringカラムの型
notnullbooleanNOT NULLを付ける
dflt_valuemixedデフォルト値(null、''、0ならデフォルトなし)
pkbooleanPRIMARY KEYを付ける
aibooleanAUTOINCREMENTを付ける

例​

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();