I need to get the identifier of the AUTO_INCREMENT value of the last request.
My query looks like this:
$result = $wpdb->query( $wpdb->prepare( "
INSERT INTO $table_name
( name, season, copyright, description, path )
VALUES ( %s, %s, %s, %s, %s )",
$galleryData['name'], $galleryData['season'], $galleryData['copyright'], $galleryData['description'], $galleryData['path'] ) );
echo $wpdb->insert_id;
echo mysql_insert_id();
Looking at my DB table, I see rows from 1 to 24 (24 rows). But use $wpdb->insert_idor mysql_insert_id()returns 241.
Performing new inserts will return 251, 261, 271, and so on. Why am I and the extra “1” at the end?
UPDATE
Thanks to Pekka (I'd rather run a tab on the amount of beer I owe him), I figured it out.
Further on the code, I got the following:
if(!$result)
_e("[DB error] Ups. Something went wrong when trying to insert the event.");
else
echo true;
This is the last expression (echo true) that is output!
source
share