Reputation: 3731
After I inserted a row I want to know it's id. Is it possible to get it in the same query with insert? Note that I'm facing the problem on PHP
Upvotes: 0
Views: 68
Reputation: 16494
or, better, for mysqli/oop:
$mysqli->query("INSERT ...");
echo $mysqli->insert_id;
http://php.net/manual/en/mysqli.insert-id.php
Upvotes: 1
Reputation: 64526
Using the mysql_* functions:
// after the query
$id = mysql_insert_id();
Using MySQLi
// after the query
$id = $mysqli->insert_id;
Using PDO
// after the query
$id = $pdo->lastInsertId();
Upvotes: 2
Reputation: 838066
Yes, you can use mysql_insert_id
mysql_insert_id — Get the ID generated in the last query
Upvotes: 3