mysql_insert_id()
my_ulonglong mysql_insert_id(MYSQL *mysql)
This function returns the identification number issued to the
primary key of the last record inserted using
INSERT in MySQL for the current connection. This
works provided the column utilizes AUTO_INCREMENT
and the value was not manually set. Otherwise, a value of 0 is
returned. Here is an example:
...
const char *sql_stmnt = "INSERT INTO workreq
(req_date, client_id, description)
VALUES(NOW( ), '1000', 'Net Problem')";
mysql_query(mysql, sql_stmnt);
my_ulonglong wr_id = mysql_insert_id(mysql);
printf("Work Request ID: %ld \n", wr_id);
...