Skip to content

lastInsertId() always returns 0 due to a reconnect to the db #39

@Serge-45

Description

@Serge-45

db()->lastInsertId() always returns 0 even after an insert into a table with an AUTO_INCREMENT column (MySQL).

Investigation shows that every call to db() reconnects to the db instead of keeping the existing connection. As a consequence, the value of lastInsertId is not kept by the PDO driver.

This is due to a mistake in src/Db/Core.php, line 361 :
361 if (!($this->connection['default'] ?? false) && $this->config('deferred')) {
shoud be replaced by
361 if (!($this->connections['default'] ?? false) && $this->config('deferred')) {
in order to use the 'default' connection created during a previous call to db().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions