我需要检索上次查询的自动增量值的ID。
我的查询如下:
$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's output the last autogenerated ID.
echo $wpdb->insert_id;
// This returns the same result
echo mysql_insert_id();
查看我的DB表,可以看到从1到24(24行)的行数。
但是使用
$wpdb->insert_id
mysql_insert_id()
回报
241
.
执行新插入操作将返回251、261、271等。为什么我要在结尾加上“1”?
更新
在代码的后面我得到了这个:
if(!$result)
_e("[DB error] Ups. Something went wrong when trying to insert the event.");
else
echo true;