php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6675 mysql_insert_id returns incorrect size for BIGINT fields
Submitted: 2000-09-12 04:54 UTC Modified: 2001-01-15 04:30 UTC
From: danbeck at dealnews dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.0 OS: Linux (redhat 6.1)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: danbeck at dealnews dot com
New email:
PHP Version: OS:

 

 [2000-09-12 04:54 UTC] danbeck at dealnews dot com
If you have a table with an auto_increment BIGINT field:

CREATE TABLE bigtest (
  id bigint(20) NOT NULL auto_increment,
  PRIMARY KEY (id)
);

and the last ID you inserted was larger than 32 bits:

i.e. 293949384923

If you insert a new record using:

  insert into bigtest values (null);

mysql_insert_id() will return an incorrect number usually negative.  It looks like it's storing that large (64bit) number in a 32bit field of some sort before returning it to the caller.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-12 21:45 UTC] danbeck@php.net
I researched this a little more and found this code snippit at line 1100:

ZEND_FETCH_RESOURCE2(mysql, MYSQL *, mysql_link, id, "MySQL-Link", le_link, le_plink);
        
/* conversion from int64 to long happing here */
return_value->value.lval = (long) mysql_insert_id(mysql);
return_value->type = IS_LONG;


Is there any way that this could be converted into a string before returning?  (Forgive me if I'm over simplifying this...)

 [2001-01-15 04:30 UTC] sniper@php.net
Feedback by Sean R. Bright <elixer@erols.com>:
----------------------------------------------
the documentation for mysql_insert_id()
states that for very large values of the returned id (>32bits) this will return the wrong data and users should use LAST_INSERT_ID() to fetch that
info from mysql instead.
----------------------------------------------


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 21:01:30 2025 UTC