توابع mysql_insert_id() PHP
تعریف و استفاده
توابع mysql_insert_id() ID تولید شده توسط عملیات INSERT قبلی را برمیگرداند.
اگر درخواست قبلی AUTO_INCREMENT ID تولید نکرده است، mysql_insert_id() 0 را برمیگرداند.
Syntax
mysql_insert_id(connection)
Parameter | Description |
---|---|
connection | Optional. Specifies the MySQL connection. If not specified, the last connection is used. |
Description
mysql_insert_id() returns the given connection in the AUTO_INCREMENT ID number generated by the previous INSERT query. If not specified connection , then use the last opened connection.
Tips and comments
Note:If you need to save this value for later use, make sure to call mysql_insert_id() immediately after the query that generates the value.
Example
<?php $con = mysql_connect(\ if (!$con) { die(\ $db_selected = mysql_select_db(\ $sql = \ $result = mysql_query($sql,$con); echo \ mysql_insert_id();; mysql_close($con); ?>
Output similar to:
ID of last inserted record is: 5