Skip to content

Commit

Permalink
Merge pull request #275 from envms/fix/insert-execute
Browse files Browse the repository at this point in the history
Add executeWithoutId() method for inserts into tables without a primary key
  • Loading branch information
cbornhoft authored Oct 30, 2018
2 parents e120999 + d3b39d9 commit 3af5c02
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Queries/Insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,37 @@ public function onDuplicateKeyUpdate($values)
*
* @throws Exception
*
* @return integer last inserted id or false
* @return int|bool - Last inserted primary key
*/
public function execute($sequence = null)
{
$result = parent::execute();

if ($result) {
return $this->fluent->getPdo()->lastInsertId($sequence);
}

return false;
}

/**
* @param null $sequence
*
* @throws Exception
*
* @return bool
*/
public function executeWithoutId($sequence = null)

This comment has been minimized.

Copy link
@roquie

roquie Oct 30, 2018

$sequence parameter real needed here?

This comment has been minimized.

Copy link
@roquie

roquie Oct 30, 2018

+ less code solution

return (bool) parent::execute()

instead of

$result = parent::execute();

if ($result) {
      return true;
}

return false;
{
$result = parent::execute();

if ($result) {
return true;
}

return false;
}

/**
* @return string
*/
Expand Down

0 comments on commit 3af5c02

Please sign in to comment.