Closed iyaozhen closed 7 years ago
When the $data
argument includes multi rows, an array contains each inserted row id will be returned. end($lastId)
gets the last element of the array and it is incorrect.
The numeric string comes from the return value of PDO::lastInsertId()
. Type-casting by force may lose precision if the underlying database use very large int as auto-increment id.
@SyuTingSong Thx, you are right.
I think should modify Documentation (http://medoo.in/api/insert). "Return: [string|array] The last insert id"
And in php documentation:
PDO::lastInsertId Note: This method may not return a meaningful or consistent result across different PDO drivers, because the underlying database may not even support the notion of auto-increment fields or sequences.
Medoo Documentation would be best warn this.
when using enter mssql with freetds, PDO::lastInsertId() [pdo.lastinsertid]: SQLSTATE[IM001]: Driver does not support this function: driver does not support lastInsertId() I add a try-catch
try {
$lastId[] = $this->pdo->lastInsertId();
}catch (Exception $e){
return 0;
}
It's updated on Medoo 1.2. Use new API id()
instead.
insert($table, $data) Return: [number] The last insert id
But in code: https://github.com/catfan/Medoo/blob/634bcef389e4eaa40d10e6d66a9eecc0f7638cc7/medoo.php#L717
It is better?