简体   繁体   中英

How do you return a value from a MySQL table after inserting a row?

I have page I have written in PHP. I am inserting a couple values as a row in one of my tables. One of the columns on that table is test_id . I want, when I INSERT the rows it to return the test_id of that row. How would I do that?

use this function mysql_insert_id

http://php.net/manual/en/function.mysql-insert-id.php

您可以使用mysql_insert_id()来获取最新插入的ID。

You can use the mysql function LAST_INSERT_ID() to find the ID that was inserted. Like this:

$query = "SELECT LAST_INSERT_ID()";

如果该行是AUTO_INCEREMENT行,则可以调用mysql_insert_id()函数来检索插入的最后一行的ID。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM