Small note: this function has a different name for each database type in PHP, so you'll have to check the manual for which function you shouold use.
Other small note: The 'last_insert_id' functions work on a connection basis. THat means, you will always get the id that was last inserted over the connection that you are currently using. That means you will never get the id of a record that someone else has just inserted.