Bug #80908 [NEW]: pdo_mysql function lastInsertId() return wrong.

From: Date: Fri, 26 Mar 2021 07:10:18 +0000
Subject: Bug #80908 [NEW]: pdo_mysql function lastInsertId() return wrong.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233002@lists.php.net to get a copy of this message
From:             atlanticfeng at icloud dot com
Operating system: Ubuntu 18.04
PHP version:      master-Git-2021-03-26 (Git)
Package:          PDO MySQL
Bug Type:         Bug
Bug description:pdo_mysql function lastInsertId() return wrong.

Description:
------------
- Latest or earlier version has this problem.
- My tests version is PHP-master-Git-2021-03-26(Git).
- In php, i use the pdo method: PDO::lastInsertId(), when MySQL table's
auto_increment id bigger than int64, eg: 10376293541461622848, the
method return a wrong result, is's like return '-8070450532247928768'.
- It's because the `static zend_string
*pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const zend_string *name)` use
funtion php_pdo_int64_to_str(int64_t i64) to convert the mysql api
funciton last_insert_id(), it should use uint64_t.
- In MySQL Reference Manual, last_insert_id With no argument,
LAST_INSERT_ID() returns a BIGINT UNSIGNED (64-bit), With an argument,
LAST_INSERT_ID() returns an unsigned integer. Is'a always greater than
zero.

Test script:
---------------
<?php

try {
    // My localhost mysql server, version is 5.7.0
    $dbh = new PDO('mysql:127.0.0.1:33060;dbname=test', 'root',
'secret');
    // In table foo, have 2 columns, primary key id
auto_increment=10376293541461622848, name is a varchar(20)
    $dbh->exec("insert into foo (name) values ('bar')");
    echo $dbh->lastInsertId() . PHP_EOL;
} catch( PDOExecption $e ) {
    print "Error!: " . $e->getMessage() . "</br>";
}

Expected result:
----------------
return "10376293541461622849"

Actual result:
--------------
return "-8070450532247928768"

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80908&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80908&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80908&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80908&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80908&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80908&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80908&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80908&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80908&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80908&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80908&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80908&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80908&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80908&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80908&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80908&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80908&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80908&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#233002) next »