-->

Tuesday, June 20, 2017

What is the BEST way to get last inserted row ID from WordPress database ?

What is the BEST way to get last inserted row ID from WordPress database ?
Answers:
1.      Use the following code snippet $lastid->$wpdb=$last->get_row;
2.      The call to mysql_insert_id() inside a transaction should be added: mysql_query(‘BEGIN’); // Whatever code that does the insert here. $id = mysql_insert_id(); mysql_query(‘COMMIT’); // Stuff with $id.
3.      The following code snippet should be added $last = $wpdb->get_row(“SHOW TABLE STATUS LIKE ‘table_name'”); $lastid = $last->Auto_increment;

4.      Straight after the $wpdb->insert() insert, the following code should be added: $lastid = $wpdb->insert_id;
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
 

Delivered by FeedBurner