How do I get the last inserted ID of a MySQL table in PHP?

后端 未结 16 2275
温柔的废话
温柔的废话 2020-11-21 23:09

I have a table into which new data is frequently inserted. I need to get the very last ID of the table. How can I do this?

Is it similar to SELECT MAX(id) FROM

16条回答
  •  隐瞒了意图╮
    2020-11-21 23:29

    Try this should work fine:

    $link = mysqli_connect("localhost", "my_user", "my_password", "world");
    
    $query = "INSERT blah blah blah...";
    $result = mysqli_query($link, $query);
    
    echo mysqli_insert_id($link);
    

提交回复
热议问题