Joomla syntax for the last inserted mysql id?

What is the joomla syntax for the last inserted mysql id?

+2


source to share


2 answers


It's just $db->insertid();

Make sure you call it right after the insert statement.



+11


source


Get db connection

$db = JFactory::getDBO();

      

Create a new request object.

$query = $db->getQuery(true);

      

Request to insert data



$query->insert('tablename')->columns('columnname')->values('custom msg');

      

Reset the request using the newly populated request object.

$db->setQuery($query);

      

Execute request

$db->execute();
$lastinsertid = $db->insertid(); // last insert id 

      

+2


source







All Articles