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

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

PHP Code:
  public function insertAny($title$slug) {
    $this->table('node')->protect(false)->place([
      '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.

P.S
Thank for your attention!
Reply

#2
CodeIgniter 4 User Guide - Query Helper Methods


PHP Code:
$db->insertID() 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
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)`
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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