Skip to main content
Version: Fegg 5.x (next)

Model::insertRow

Insert a row from an associative array

Description​

public int|string Model::insertRow( array $row )

Inserts one row from column => value pairs and returns the new ID (an int for integer keys).

  • Only the given columns are written; null is stored as NULL.
  • created, modified and valid are filled automatically. Give them only to override them.
  • bind types are applied.
  • Throws InvalidArgumentException for an empty array, a column name that is not a plain name, or a value that is an array or an object. A failed insert (for example a duplicate key) throws Fegg\Database\QueryException.

Arguments​

NameData typeDefaultRemarks
$rowarrayValues (column => value)

Example​

Controller
$model = new Model(true, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));

$id = $model->insertRow(array(
'title' => $this->in('title'),
'category' => 2,
'post_date' => '2026-01-15 10:00:00',
'image_id' => null,
));
// -> 24