Skip to content

Instantly share code, notes, and snippets.

@scarpent
Last active December 17, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scarpent/5546366 to your computer and use it in GitHub Desktop.
Save scarpent/5546366 to your computer and use it in GitHub Desktop.
function getNextSequenceNumber($sequenceName)
{
global $wpdb;
$wpdb->query($wpdb->prepare(
"
INSERT INTO table_name
(seq_name, seq_num)
VALUES (%s, LAST_INSERT_ID(1))
ON DUPLICATE KEY UPDATE seq_num = LAST_INSERT_ID(seq_num + 1);
",
$seq_name
));
return $wpdb->get_var("SELECT LAST_INSERT_ID();");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment