[REVIEW] database->insertid

Last reviewed: Not reviewed


Returns the unique record number of the last record to be inserted into a database table.


int insertid ( )


Example: This example creates a new, default record in the users table and returns the unique id allocated to that user.

// Returns unique id of new user record or false
// if the insert failed.
function newUser() {
  global $database;
  $sql = 'INSERT INTO #__users () VALUES()';
  $database->setQuery( $sql );
  if (!$database->query()) {
    echo $database->stderr();
    return false;
  return $database->insertid();

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Monday, 25 December 2006 )