admin管理员组文章数量:1429201
I am trying to get a primary key from a coupon table to put it in my target table as a foreign key. In between I would like to run a query to get the last insert id. I can't get the syntax right though
$couponId = $wpdb->query("select last_insert_id() from frequentVisitorCoupons_coupons");
var_dump($couponId); // false
$couponId = $wpdb->query("select * from frequentVisitorCoupons_coupons where last_insert_id()");
var_dump($couponId); // false
What is the correct syntax for this query?
I am trying to get a primary key from a coupon table to put it in my target table as a foreign key. In between I would like to run a query to get the last insert id. I can't get the syntax right though
$couponId = $wpdb->query("select last_insert_id() from frequentVisitorCoupons_coupons");
var_dump($couponId); // false
$couponId = $wpdb->query("select * from frequentVisitorCoupons_coupons where last_insert_id()");
var_dump($couponId); // false
What is the correct syntax for this query?
Share Improve this question asked May 1, 2019 at 3:07 Sean DSean D 3878 silver badges21 bronze badges1 Answer
Reset to default 2You can get the last inserted ID from $wpdb
with the insert_id
property:
$wpdb->insert( ... );
$couponId = $wpdb->insert_id
本文标签: databaseTrouble running wpdbgtquery() with lastinsertid
版权声明:本文标题:database - Trouble running $wpdb->query() with last_insert_id 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745536678a2662303.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论