后插入MySQL的检索ID
问题描述:
海兰,
有没有一种方法,在mysql数据库(INSERT INTO table_name VALUES() ...
)将东西取回的ID后插入进一步操作?
旧的方法是进行插入,然后在表名上查询SELECT
。但有没有办法在单个查询中做到这一点?
非常感谢您
答
在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();
重复: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 –