Is it possible to get lastInsertId()
from a method, and also if possible get the value from a specific table?
The method I try to use is in my db.class.php
public function getLastID(){
$dbh = $this->db_connect();
if($dbh){
try{
$lastId = $dbh->lastInsertId();
return $lastId;
}
catch(PDOException $err){
return $err->getMessage();
}
}
else{
return false;
}
}
When I access the method, echo $db->getLastID();
, the value I get is 0
.
return $db->lastInsertId('column');
OR
$db->getDbh()->lastInsertId();
stackoverflow.com/questions/10809752/how-to-use-pdolastinsertid