database - Trouble running $wpdb->query() with last_insert_id

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 l

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 badges
Add a comment  | 

1 Answer 1

Reset to default 2

You can get the last inserted ID from $wpdb with the insert_id property:

$wpdb->insert( ... );
$couponId = $wpdb->insert_id

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745536679a4631937.html

相关推荐

  • database - Trouble running $wpdb->query() with last_insert_id

    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 l

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信