my_ulonglong mysql_insert_id(MYSQL *mysql)
20.4.29.1  Description
Returns the ID generated for an AUTO_INCREMENT column by the previous
query.  Use this function after you have performed an INSERT query
into a table that contains an AUTO_INCREMENT field.
Note that mysql_insert_id() returns 0 if the previous query
does not generate an AUTO_INCREMENT value.  If you need to save
the value for later, be sure to call mysql_insert_id() immediately
after the query that generates the value.
Also note that the value of the SQL LAST_INSERT_ID() function always
contains the most recently generated AUTO_INCREMENT value, and is
not reset between requêtessince the value of that function is maintained
in the server.
20.4.29.2  Return values
The value of the AUTO_INCREMENT field that was updated by the previous
query.  Returns zero if there was no previous query on the connection or if
the query did not update an AUTO_INCREMENT value.
20.4.29.3  Errors
None.