The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inserted objects ID
#1
Is there a way to get the ID of last inserted object?
  Reply
#2
In the DB.php class file, there is the following function you can use on the PDO object.

public function lastId(){
return $this->_lastId;
}
  Reply
#3
I added that function because that issue always baffled me, and then I never actually used it in writing userspice.

Let's say you want to add a new user named Bob to your database whenever someone visited your homepage (which wouldn't be advised).

Code:
<?php
Code:
$fields=array('username'=>"bob");
Code:
$db->insert('users',$fields);
Code:
$lastId = $db->lastId();
Code:
echo $lastId;
Code:
?>

Loading this page would echo out the latest "Bob" user id.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)