Welcome Guest, Not a member yet? Register   Sign In
Model return id record
#1

(This post was last modified: 06-30-2019, 07:10 AM by Nome.)

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




Theme © iAndrew 2016 - Forum software by © MyBB