I am trying to fetch the last inserted ID from MySQL database in PHP and I was wondering what would be the best way to do it?
I am currently using this kind of solution, but there has to be a better and safer way. So would someone please help me? Thanks
Some insert statement...
$query = "SELECT MAX(aid) FROM asset";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$pickassssult= $row['MAX(aid)'];
}
PHP has a function called:
more info
http://lt.php.net/manual/en/function.mysql-insert-id.php