mysql_insert_id() returns 0
Posted: Thu Feb 03, 2011 3:26 pm
Hi, I'm trying to use the mysql_insert_id() php function to have the last inserted id after an INSERT STATEMENT, but the function always returns 0 (zero).
- I have a table, "MyTable", with AUTO INCREMENT ID
- I make:
$query = 'INSERT INTO '.cms_db_prefix().'MyTable (a,b) VALUES ('a-value,'b-value')';
$dbr = $db->Execute($query)
hence:
$new_generated_id = mysql_insert_id();
The new record is correctly added to "MyTable" with the new id, but $new_generated_id is always 0.
Any suggestion?
thank you
- I have a table, "MyTable", with AUTO INCREMENT ID
- I make:
$query = 'INSERT INTO '.cms_db_prefix().'MyTable (a,b) VALUES ('a-value,'b-value')';
$dbr = $db->Execute($query)
hence:
$new_generated_id = mysql_insert_id();
The new record is correctly added to "MyTable" with the new id, but $new_generated_id is always 0.
Any suggestion?
thank you