diff --git a/src/Medoo.php b/src/Medoo.php index 15ba427b..6d68f4c2 100644 --- a/src/Medoo.php +++ b/src/Medoo.php @@ -360,13 +360,16 @@ public function exec($query, $map = []) $statement->bindValue($key, $value[ 0 ], $value[ 1 ]); } - $statement->execute(); - - $this->statement = $statement; + if ($statement->execute()) + { + $this->statement = $statement; - return $statement; + return $statement; + } } + $this->statement = null; + return false; } @@ -1736,6 +1739,11 @@ public function action($actions) public function id() { + if ($this->statement == null) + { + return null; + } + $type = $this->type; if ($type === 'oracle') @@ -1747,7 +1755,14 @@ public function id() return $this->pdo->query('SELECT LASTVAL()')->fetchColumn(); } - return $this->pdo->lastInsertId(); + $lastId = $this->pdo->lastInsertId(); + + if ($lastId != "0" && $lastId != "") + { + return $lastId; + } + + return null; } public function debug()