Possible Duplicate:
(mysql, php) How to get auto_increment field value before inserting data?
I have this table which is for users. the user_id is an auto increment field. I’m using PDO to connect and execute to the database. How I can get the user_id value after adding a new user?
I’ve tried to user mysql_insert_id(), but nothing happened.
$sql = "INSERT INTO `users` (`user_name` ,`user_password` ,) VALUES (?, ?)";
$db = new DB; // create Database handler.
if($db->execute($sql,$this->name,$this->password))
{
$this->permission = new permission(mysql_insert_id()); // <--- HERE
$this->permission->reset();
$this->permission->insert();
}
return true;
because the new class will be constructed base on a user_id value. Thank you in advance.
mysql_insert_id() is not PDO. Have you tried $db->lastInsertId() after $db->execute?