Why does $ wpdb-> insert_id and mysql_insert_id () return with an extra "1" at the end?

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'] ) );

  // Let output the last autogenerated ID.
  echo $wpdb->insert_id;

  // This returns the same result
  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!

+3
source share
1 answer

Kölsch:

alt text

echo , , true 1.

, , .

( , , :)

: , , !

+14

Source: https://habr.com/ru/post/1770210/


All Articles