May 2005
Intermediate to advanced
352 pages
14h 39m
English
mysql_insert_id( )
my_ulonglong mysql_insert_id(MYSQL *mysql)
This 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, 0 is returned.
...
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);
...Read now
Unlock full access