Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Insert multiple rows with one db-action
  • Is ist possible to insert multiple rows with one action.
    For example. I habe a table "tags" and want to save a few tag.
    now I am doing it so:
    $tag_array = array('tag1', 'tag2');
    foreach($tag_array as $tag)
    {
    Model_Tag->forge()->set('tag', $tag)->save();
    }

    (Pseudocode: code type here for demonstarated)
  • HarroHarro
    Accepted Answer
    No, not via ORM.

    An ORM is an object relational mapper, which maps individual records to objects (and the other way around). An ORM is not a query builder that you can use to generate arbitrary queries, you  need to use the query builder (DB) for that.

    DB::insert() supports multiple inserts at once if you use the values() method instead of set(), and you pass an array of rows to it.
  • Thank You!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion