Closed harryqt closed 4 years ago
Describe the bug
$database->id() returns NULL even after a successful insert()
$database->id()
NULL
insert()
Information
Detail Code
$database = new Medoo\Medoo([ 'database_type' => 'mysql', 'database_name' => 'dbname', 'server' => 'localhost', 'username' => 'root', 'password' => '' ]); $query = $database->insert('table_copy', [ 'id' => 59093903, 'api_response' => serialize(str_repeat('test', 5)) ]); // Here the lastInsertId() returns NULL which is incorrect. var_dump($database->id()); // returns "0" (string) which is also incorrect. var_dump($database->pdo->lastInsertId()); // However rowCount() returns 1 (int) which is correct. var_dump($query->rowCount());
The id() or lastInsertId() from PDO, is for returning the auto-increase id last inserted. The id of non-key or not auto-increase column will not be return.
id()
lastInsertId()
You may need to know how database engine works.
Describe the bug
$database->id()
returnsNULL
even after a successfulinsert()
Information
Detail Code