Table of Contents

insertid

API Package Subpackage Class Method Reference Last reviewed Doc status
API Home Package Joomla.Framework Subpackage Database Class JDatabase Method insertid Reference insertid() Never Work in Progress

Gets the ID generated from the previous INSERT operation. This method is a wrapper for the database specific method.

Syntax

integer insertid ()

Examples

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

Example

$database =& JFactory::getDBO();
$sql = 'INSERT INTO #__contact_details (name) VALUES("PEDRO")';
$database->setQuery( $sql );
if (!$database->query()) {
  echo $database->stderr();
} else {
  echo $database->insertid();
}

might produce:

Result

2