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.
The topic ‘SQL Next ID?’ is closed to new replies.