Joomla syntax for mysql last inserted id?
Wh开发者_JAVA技巧at is the joomla syntax for mysql last inserted id?
It's just $db->insertid();
Ensure you call it immediately after the insert statement.
Get db connection
$db = JFactory::getDBO();
Create a new query object.
$query = $db->getQuery(true);
Query to insert data
$query->insert('tablename')->columns('columnname')->values('custom msg');
Reset the query using newly populated query object.
$db->setQuery($query);
Execute the query
$db->execute();
$lastinsertid = $db->insertid(); // last insert id
精彩评论