Title: SQL Next ID?
Last modified: August 18, 2016

---

# SQL Next ID?

 *  [Jasmeralia](https://wordpress.org/support/users/stormerider/)
 * (@stormerider)
 * [19 years, 2 months ago](https://wordpress.org/support/topic/sql-next-id/)
 * I’m working on writing a plugin for WordPress to create progress meters for authors
   to use. (I run a WP-MU for authors and host a few author WP sites as well.)
 * The original code that I wrote this for was integrated with phpBB and I’ve been
   porting it over to WordPress with very little issue. However, one problem that
   I am finding is that I’m not sure how to retrieve the ID of an auto-incrementing
   index field when I perform a SQL INSERT query. Normally I would do this with 
   mysql_insert_id(), but I don’t see an equivalent method in WordPress’s DB class.
 * How do you recommend I go about handling this? I could, I suppose, do a SELECT
   key_id FROM table ORDER BY key_id DESC LIMIT 1, LOCK the table, perform the INSERT
   with key_id+1, then UNLOCK the table, but this seems very inelegant… especially
   when applied to a WP-MU setup where multiple users may be trying to add new meters
   at the same time. (Granted the granularity of access time is unlikely to bottleneck
   on a table lock, but I still prefer to avoid them whenever possible as they simply
   do not scale well.)
 * Any suggestions would be much appreciated.

Viewing 1 replies (of 1 total)

 *  Thread Starter [Jasmeralia](https://wordpress.org/support/users/stormerider/)
 * (@stormerider)
 * [19 years, 2 months ago](https://wordpress.org/support/topic/sql-next-id/#post-529525)
 * Nevermind, I found it… I can actually access this through the SQL server directly
   via SELECT LAST_INSERT_ID(). 🙂

Viewing 1 replies (of 1 total)

The topic ‘SQL Next ID?’ is closed to new replies.

## Tags

 * [development](https://wordpress.org/support/topic-tag/development/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * 1 reply
 * 1 participant
 * Last reply from: [Jasmeralia](https://wordpress.org/support/users/stormerider/)
 * Last activity: [19 years, 2 months ago](https://wordpress.org/support/topic/sql-next-id/#post-529525)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
