title: Why is $wpdb->insert_id and mysql_insert_id() returning with an extra '1' at the end?
body: <p>I need to retrieve the ID of the AUTO_INCREMENT value of the last query.</p>
  
  <p>My query looks like this:</p>
  
  <pre><code>  $result = $wpdb-&gt;query( $wpdb-&gt;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's output the last autogenerated ID.
    echo $wpdb-&gt;insert_id;
  
    // This returns the same result
    echo mysql_insert_id();
  </code></pre>
  
  <p>Looking at my DB table, I see rows counting from 1 to 24 (24 rows).
  But using <code>$wpdb-&gt;insert_id</code> or <code>mysql_insert_id()</code> returns <code>241</code>.</p>
  
  <p>Doing new inserts will return 251, 261, 271 and so on. Why do I et the extra '1' at the end?</p>
  
  <p><strong>UPDATE</strong><br>
  Thanks to Pekka (I'd better stad running a tab on the number of beers I owe him), I figured it out.</p>
  
  <p>Further down the code I got this:</p>
  
  <pre><code>  if(!$result)
      _e("[DB error] Ups. Something went wrong when trying to insert the event.");
    else
      echo true;
  </code></pre>
  
  <p>It's the last statement (echo true) that is outputed!</p>