从 wordpress $wpdb 获取最后插入的 id
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3777450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get last inserted id from wordpress $wpdb
提问by Aadi
I would like to get last inserted id after $wpdb->insert().I got a solution with $wpdb->insert_id();
but unfortunately which retrieves the primary key plus an additional zero.
ie, consider my primary key (or inserted id) is 2 $wpdb->insert_id();
retruns 20 .whats wrong with this method?anybody can please help me.
我想在 $wpdb->insert() 之后获得最后插入的 id。我得到了一个解决方案,$wpdb->insert_id();
但不幸的是它检索主键加上一个额外的零。即,考虑我的主键(或插入的 id)是 2 次$wpdb->insert_id();
retruns 20。这个方法有什么问题?任何人都可以帮助我。
回答by jay.lee
The insert_id
is a property, not a method. Try it without the ()
at the end, see what you get.
该insert_id
是一个属性,而不是方法。尝试在没有()
结尾的情况下,看看你会得到什么。