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

Pdo::insert

INSERTのクエリを組み立てます

説明​

public self Pdo::insert( string $table )

setValues(またはsetItem)で設定した値から、$tableへのINSERTを組み立てます。created、modified、validは、指定しなければ自動で付きます(設定を参照)。executeで実行し、新しいIDはgetLastIndexIdで読みます。

引数​

名前データ型デフォルト備考
$tablestring対象テーブル名

例​

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

// Insert Into "cms_news" ("title", "category", modified, created, valid) Values (?, ?, ?, ?, ?)
$db->setValues(array('title' => 'Sample', 'category' => 2))->insert('cms_news')->execute();
$id = $db->getLastIndexId();
// -> '24'