0

I am using the Model_CRUD class and it's methods to save and find in database. The problem comes when saving new object into DB, is how to get last inserted id ?

User::forge($userInfo)->save(); // Save returns only bool value

Does this requires one query more to get last inserted id ?

Risto Novik
  • 8,199
  • 9
  • 50
  • 66

1 Answers1

2

You don't have to do an extra query to fetch the last inserted id. Just try the following code:

$user = User::forge($userInfo);
$user->save();

$last_id = $user->id;

You should check the Model_Crud documentation for further info.

Quetzy Garcia
  • 1,820
  • 1
  • 21
  • 23