我需要检索上一个查询的AUTO_INCREMENT值的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();
Run Code Online (Sandbox Code Playgroud)
查看我的数据库表,我看到行数从1到24(24行).但使用$wpdb->insert_id或mysql_insert_id()返回241.
执行新插入将返回251,261,271等.为什么我最后加上额外的'1'?
更新
感谢Pekka(我最好坚持运行我欠他的啤酒数量的标签),我想通了.
在代码的下面我得到了这个:
if(!$result)
_e("[DB error] Ups. Something went wrong when trying to insert the event.");
else
echo true;
Run Code Online (Sandbox Code Playgroud)
这是最后一个声明(echo true)!
Pek*_*ica 15
我打赌美味的Kölsch:

原因实际上是echo在代码的后面,它回应了一些布尔变量,true它将转换为1.
如果我错了,我会像男人一样接受投票.
(原谅这个愚蠢的回答,已经很晚了,我还在工作:)
更新:啊,快乐,我是对的!
| 归档时间: |
|
| 查看次数: |
9539 次 |
| 最近记录: |