| API | Package | Subpackage | Class | Method | Reference | Last reviewed | Doc status |
|---|---|---|---|---|---|---|---|
Home |
Joomla.Framework |
Database |
JDatabase |
insertid |
insertid() |
Never | Work in Progress |
Gets the ID generated from the previous INSERT operation. This method is a wrapper for the database specific method.
integer insertid ()
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