note 13210 deleted from function.mysql-insert-id by sander

From: Date: Sat, 18 May 2002 07:15:37 +0000
Subject: note 13210 deleted from function.mysql-insert-id by sander
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-30790@lists.php.net to get a copy of this message
Since I spent some time on this topic I thought I should show others how I solved it for myself. Try the following: function connectDB($query) { global $gMainDbHost, $gMainDbName, $gMainDbUser, $gMainDbPass; $link = mysql_pconnec($gMainDbHost, $gMainDbUser, $gMainDbPass) or die("Could not connect"); $status = mysql_select_db($gMainDbName, $link) or die("Could not select $gMainDbName"); $result = mysql_query($query) or print("<li> Query Failed: </li>\n" . "<li> errorno = " . mysql_errno() . "</li>\n" . "<li> error = " . mysql_error() . "</li>\n" . "<li> query = " . $query . "</li>\n"); $status = mysql_close($link); return($result); } $query = "SELECT LAST_INSERT_ID()"; $result = connectDB($query); if ($result) { $nrows = mysql_num_rows($result); $row = mysql_fetch_row($result); $lastID = $row[0]; } This seems to work on all my tables so I think it is fairly solid. If you see a flaw - please let me know.

« previous php.notes (#30790) next »