How to get the last insert id from $GLOBALS['db']->query?

How to get the last insert id from $GLOBALS['db']->query after running an insert sql statement?

If there a build up function for it?

Thanks!!