2009-10-04 65 views

回答

4

參見mysql_insert_id

mysql_insert_id - 獲取ID生成 從先前的插入操作

示例(來自手冊):

<?php 
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db('mydb'); 

mysql_query("INSERT INTO mytable (product) values ('kossu')"); 
printf("Last inserted record has id %d\n", mysql_insert_id()); 
?> 

要檢索使用mysqli最後自動生成密鑰,見mysqli->insert_id

+0

感謝。但我忘了說,我只能用的mysqli類 – Johannes 2009-10-04 09:57:13

+2

http://sk.php.net/manual/en/mysqli.insert-id.php – 2009-10-04 09:58:34

+0

我現在可以看到,這個方法也是在mysqli的使用。 。 非常感謝 ;) – Johannes 2009-10-04 09:58:34