List:Internals« Previous MessageNext Message »
From:FOURNIER Jacques - GRE Date:September 28 2000 5:01pm
Subject:Value of an automatically generated ID
View as plain text  
How to get the value of an automatically generated ID ?

I have read the following chapter of the mySQL documentation :
18.5 How to get the value of an AUTO_INCREMENT column in ODBC
but the solution given doesn't work for me !

This chapter said that just after an insert command, the following
command must be done :
but no data is selected with this command.

Here is my (php) code, flightNum is my auto_increment column :
  $sql  = "INSERT INTO cfdFlights (flightNum,licence) VALUES
  $sql2         = "SELECT LAST_INSERT_ID()";
  $result       = mysql_query($sql,$conn);
  $resultLast   = mysql_query($sql2,$conn);

   $newFlightNum = mysql_result($resultLast, 0, "flightNum");
And there is nothing in my variable $newFlightNum after that.

What can I do ?

Even if this solution works, is it a good solution ? Because if between
my insert command and my select command, another program make an insert
command, I think I have the risk to have a wrong ID...

Thanks in advance.

 Jacques Fournier
 Grenoble Email : jacques.fournier@stripped
 Other Email      : jacquesf@stripped

Value of an automatically generated IDFOURNIER Jacques - GRE1 Oct
  • Re: Value of an automatically generated IDPaul DuBois1 Oct