mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 14:50:39 -04:00
Throw exception when last insert ID can't be determined
This commit is contained in:
parent
e5973c8938
commit
ace9cea6b7
1 changed files with 14 additions and 11 deletions
|
@ -400,21 +400,24 @@ class DbConnection{
|
|||
}
|
||||
}
|
||||
|
||||
public function GetLastInsertedId(): ?int{
|
||||
$id = $this->_link->lastInsertId();
|
||||
/**
|
||||
* Get the ID of the last row that was inserted during this database connection.
|
||||
* @throws Exceptions\DatabaseQueryException When the last inserted ID can't be determined.
|
||||
*/
|
||||
public function GetLastInsertedId(): int{
|
||||
try{
|
||||
$id = $this->_link->lastInsertId();
|
||||
}
|
||||
catch(\PDOException){
|
||||
$id = false;
|
||||
}
|
||||
|
||||
if($id === false){
|
||||
return null;
|
||||
if($id === false || $id == '0'){
|
||||
throw new Exceptions\DatabaseQueryException('Couldn\'t get last insert ID.');
|
||||
}
|
||||
else{
|
||||
$id = (int)$id;
|
||||
return intval($id);
|
||||
}
|
||||
|
||||
if($id == 0){
|
||||
return null;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue