Pdo::createTable
CREATE TABLEのクエリを組み立てます
説明
public self Pdo::createTable( string $table, array $field )
Create Tableを組み立てます。テーブルは通常、site/config/database/*.yamlで定義し、./fegg-cli migrationで作成します。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $table | string | テーブル名 | |
| $field | array | カラムの定義の一覧(下記) |
カラムの定義
すべてのキーを指定します。
| キー | データ型 | 備考 |
|---|---|---|
name | string | カラム名 |
type | string | カラムの型 |
notnull | boolean | NOT NULLを付ける |
dflt_value | mixed | デフォルト値(null、''、0ならデフォルトなし) |
pk | boolean | PRIMARY KEYを付ける |
ai | boolean | AUTOINCREMENTを付ける |
例
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();