• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Model return id record

What are the ways to return the id of the created record in the table?

PHP Code:
  public function insertAny($title$slug) {
      'title'    => $title,
      'slug'     => $slug
    return ID of record? ;

Because I have only one idea, this is to create an additional unique field on which, after executing the record, perform a search and return the ID. But I think there should be some solution out of the CI box.

Thank for your attention!

CodeIgniter 4 User Guide - Query Helper Methods

PHP Code:
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

What @InsiteFX said. Also if you do your insert through a Model you can use the method `getInsertID()` that will return the last insert handle *by that model*. This can also be returned directly from the insert statement using the second parameter: `$insertID = $model->insert($row, true)`

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.