Skip to content

Commit

Permalink
[fix] Incorrect id() result for after executing query with error #871
Browse files Browse the repository at this point in the history
  • Loading branch information
catfan committed Oct 11, 2019
1 parent 113519d commit b3f05ed
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/Medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1736,6 +1739,11 @@ public function action($actions)

public function id()
{
if ($this->statement == null)
{
return null;
}

$type = $this->type;

if ($type === 'oracle')
Expand All @@ -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()
Expand Down

0 comments on commit b3f05ed

Please sign in to comment.