RE: [PHP] mysql_insert_id

From: Date: Tue, 26 Sep 2000 13:54:32 +0000
Subject: RE: [PHP] mysql_insert_id
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17615@lists.php.net to get a copy of this message
Try this function to get the last id that was inserted on a table: function get_last_id($table) { $SQL = "SELECT LAST_INSERT_ID() from $table"; $result = mysql_query( $SQL); $Err = mysql_error(); $numrows = mysql_num_rows($result); $row = mysql_fetch_array($result); $id = $row[0]; //echo ("Table $table last id was $id."); return $id; } pj -----Original Message----- From: Boget, Chris [mailto:Chris.Boget@wild.net] Sent: Tuesday, September 26, 2000 9:22 AM To: 'scottrus@ipass.net'; 'php-general@lists.php.net' Subject: RE: [PHP] mysql_insert_id > > I'm inserting data into a table with an auto_increment > > field. The data is going in perefectly (with the A_I field > > incrementing as it should; I can see this is true in the DB) > > and there is no errors being returned. > > However, when I try to executed the mysql_insert_id() > > function (immediately after the query), it is returning > > '0' (zero). Why? > > Here is my field definition: > > | ticket_number | int(15) unsigned | | PRI | 0 | > > auto_increment | > > I cannot see in the docs why it would fail and unfortunately, > > mysql_insert_id() does not return why it would have failed > > getting the auto_increment value. > > I'm using PHP 3.0.5 and any help anyone could offer would > > be greatly appreciated!! > Try calling the mysql_insert_id($dbh) where $dbh is the link > identifier from the mysql_pconnect() or mysql_connect() > function. Update: when I pass the result returned by the mysql() function call, mysql_insert_id() returns '0' (zero). But when I do not pass any arguments to the mysql_insert_id() function, it returns the correct value. Why? Shouldn't it work properly either way? Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#17615) next »