You can call the mysql_stmt_insert_id() function to return the value generated by a prepared INSERT or UPDATE statement for an AUTO_INCREMENT column.
Syntax
my_ulonglong
mysql_stmt_insert_id(MYSQL_STMT *stmt)
Return values
The value for the AUTO_INCREMENT column which was automatically generated or explicitly set during the execution of the prepared statement, or the value generated by the LAST_INSERT_ID(expr) function is returned.
The return value is undefined if the statement does not set an AUTO_INCREMENT value.
Errors
None.
Notes
Call this function after the INSERT statement is executed for tables containing the AUTO_INCREMENT field.