PHP mysql_insert_id()
mysql_insert_id()可以直接取得剛剛 insert 產生的 id。
PHP mysql_insert_id()函數
- <?php
- $con = mysql_connect("localhost", "hello", "321");
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- $db_selected = mysql_select_db("test_db",$con);
- $sql = "INSERT INTO person VALUES ('Carter','Thomas','Beijing')";
- $result = mysql_query($sql,$con);
- echo "ID of last inserted record is: " . mysql_insert_id();
- mysql_close($con);
- ?>
PHP mysql_insert_id()函數
留言