Skip to content

Commit e63e382

Browse files
committed
Added DataMapper::lastError() method.
1 parent f23c76a commit e63e382

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/DataMapper/DataMapper.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ public function lastSQL(): string
121121
return $this->last_sql;
122122
}
123123

124+
/**
125+
* @inheritDoc
126+
*/
127+
public function lastError(): ?string
128+
{
129+
if(!isset($this->statement)){
130+
return null;
131+
}
132+
$errorCode = $this->statement->errorCode();
133+
if($errorCode === null || empty(\trim($errorCode, "0 \t\n\r\0\x0B"))){
134+
return null;
135+
}
136+
$errorInfo = $this->statement->errorInfo();
137+
if(!isset($errorInfo[2])){
138+
return null;
139+
}
140+
return $errorCode . ' - ' . $errorInfo[2];
141+
}
142+
124143
/**
125144
* @inheritDoc
126145
*/

src/DataMapper/DataMapperInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public function prepare(string $sqlQuery): self;
3232
*/
3333
public function lastSQL(): string;
3434

35+
/**
36+
* @return string|null
37+
*/
38+
public function lastError(): ?string;
39+
3540
/**
3641
* @param $value
3742
* @return mixed

0 commit comments

Comments
 (0)