How to get last insert id after insert in Joomla database?

Get last id
Joomla solution for get last insert ID after insert a new row in J! database:

$db->insertid();

Example ↓

$query = $db->getQuery(true);
$query->insert('#__test_table');
$query->set('`user_id`='.(int)$uid);
$db->setQuery($query);
$db->query();
$last_id = $db->insertid();

In native PHP ↓
Object oriented style

$last_id = $mysqli->insert_id;

Continue reading How to get last insert id after insert in Joomla database?