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
  • 7,973
  • 9
  • 48
  • 65

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,810
  • 1
  • 22
  • 23