LAST_INSERT_ID only returning 0
Posted: Fri Aug 15, 2008 7:15 am
Hi all,
I had a search through the forum for my problem and have checked all the obvious stuff. We recently changed one of our apps from MySQLi to MySQL. We were using mysqli_insert_id to return the last inserted id, but due to the change we moved everything about and the new code only returns 0.
Above are the two methods in question. The connection class holds all the information of the connection, and the directExecute method of this class simply runs what ever query it is set using this connection. Right after the query has been executed I call the getLastId method that should return the last inserted id. However this only returns 0.
The tables key field contains an auto increment number, so that part is ok, and no other queries are run after the INSERT so that should be ok. Does any one have any idea why I keep getting 0 returned??
Thanks All!
I had a search through the forum for my problem and have checked all the obvious stuff. We recently changed one of our apps from MySQLi to MySQL. We were using mysqli_insert_id to return the last inserted id, but due to the change we moved everything about and the new code only returns 0.
Code: Select all
public function addBlankItem()
{
$sql = "INSERT INTO paxProfile () VALUES ()";
$this->connection->directExecute( $sql );
$this->lastID = $this->connection->getLastID();
}
public function getLastID()
{
$sql = "SELECT LAST_INSERT_ID() AS id";
$RS = mysql_query($sql, $this->dataConnection);
$row = mysql_fetch_assoc($RS);
return $row;
}
The tables key field contains an auto increment number, so that part is ok, and no other queries are run after the INSERT so that should be ok. Does any one have any idea why I keep getting 0 returned??
Thanks All!