后插入MySQL的检索ID

问题描述:

可能重复:
mySQL return index after insert后插入MySQL的检索ID

海兰,

有没有一种方法,在mysql数据库(INSERT INTO table_name VALUES() ...)将东西取回的ID后插入进一步操作?

旧的方法是进行插入,然后在表名上查询SELECT。但有没有办法在单个查询中做到这一点?

非常感谢您

+1

重复:http://stackoverflow.com/questions/2666277/mysql-return-index-after-insert http://stackoverflow.com/questions/5667614/mysql-last-insert-id-and-found-rows http://stackoverflow.com/questions/2266604/select-last-insert-id –

在PHP中,调用mysql_insert_id()。或者直接在MySQL中调用LAST_INSERT_ID()函数。

// PHP 
echo mysql_insert_id(); 

// PHP MySQLi 
echo $mysqli->insert_id; 

-- in MySQL 
SELECT LAST_INSERT_ID(); 
+0

我使用' mysqli'函数... – pufos

+0

问题是..在那一刻可能有很多插入...我只想要ID f从那个特定的插入。 – pufos

+0

@pufos看到另外 –

您有一个名为

$lastId = mysql_insert_id(); 

更多信息功能:http://php.net/manual/en/function.mysql-insert-id.php