Anvano
Зарегистрирован: 24.03.2005 Сообщения: 58
|
Добавлено: Чт Авг 04 2005 16:36 Заголовок сообщения: |
|
|
В PHP, например, для этого есть специальная функция
mysql_insert_id - возвращает значение автоинкрементного столбца таблицы, полученное в результате последнего INSERT`а в эту таблицу
----------------------------------------------------------------------
mysql_insert_id
Get the ID generated from the previous INSERT operation (PHP 3, PHP 4 )
int mysql_insert_id ( [resource link_identifier ] )
mysql_insert_id() returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.
mysql_insert_id() returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call mysql_insert_id() immediately after the query that generates the value.
Код: |
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
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());
?>
|
|
|