FaaPz / PDO

Just another PDO database library
MIT License
316 stars 103 forks source link

InsertStatement execute problem #17

Closed srgzah closed 8 years ago

srgzah commented 8 years ago

Hi,

$insertStatement = $pdo->insert($fields)->into('accounts')->values($values);
$insertId = $insertStatement->execute();

$insertId is always <= 0 and nothing is inserted.

To fix this I need to do lke this:

$insertId = $insertStatement->execute(false); // now it is OK.

Why you do this?

public function execute($insertId = true){
        if (!$insertId) {
            return parent::execute();
        }

        return $this->dbh->lastInsertId();
}

Thanks.

FaaPz commented 8 years ago

That's because of PR #13. But I've made a sloppy mistake, that was fixed later on in PR #15.

Just released v1.9.4 (65d415f9b32ef769bfc11d2440ee975332c02921) with everything working correctly.

Now, if you don't want to receive the $insertId, the you should call: execute(false) If you want to receive the $insertId, do nothing. :wink:

srgzah commented 8 years ago

:+1: