Örnek: Ben PHP'nin PDO yerleşik kullanarak, bu ile veritabanına bir satır eklemek:
$sql = "INSERT INTO mytable (name, ok) VALUES ('john', '1')";
$this->dbh->exec($sql);
Ben bu satırın id gerekir. Bunu nasıl alabilir?
id
ise bir auto_increment
, kullanabilirsiniz PDO::lastInsertId
a>:
Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver.
So, in your case, something like this should do the trick :
$lastId = $this->dbh->lastInsertId();