php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53152 mysql_insert_id return 0
Submitted: 2010-10-25 18:50 UTC Modified: 2010-11-19 17:24 UTC
From: genix at arctoz dot de Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.3.3 OS: Linux 2.6.34.6-54.fc13.i686
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: genix at arctoz dot de
New email:
PHP Version: OS:

 

 [2010-10-25 18:50 UTC] genix at arctoz dot de
Description:
------------
When calling mysql_insert_id() after insert, php returns 0, but if queried "SELECT LAST_INSERT_ID()" it returns the right value.

Test script:
---------------
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");

mysql_query("INSERT INTO table VALUES('', 'TEST')");

echo "LAST-ID (Function): " . mysql_insert_id() . "\n";

$res = mysql_query("SELECT LAST_INSERT_ID() as LID");
$r = mysql_fetch_assoc($res);

echo "LAST-ID (Query): " . $r['LID'];
?>

Expected result:
----------------
LAST-ID (Function): 38
LAST-ID (Query): 38

Actual result:
--------------
LAST-ID (Function): 0
LAST-ID (Query): 38

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-27 03:05 UTC] uramihsayibok at gmail dot com
The INSERT query is invalid - "table" is a reserved word.

Using
> CREATE TABLE `table` (id INT AUTO_INCREMENT PRIMARY KEY, foo TEXT)
> mysql_query("INSERT INTO `table` VALUES('', 'TEST')");
it works for me. Which isn't surprising considering a bug this obvious would have 
been noticed a long time ago.

Check your MySQL client and server versions and/or give a real, self-contained 
test script.
 [2010-11-19 17:24 UTC] Kalle@php.net
-Status: Open +Status: Bogus
 [2010-11-19 17:24 UTC] Kalle@php.net
.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 02:01:29 2024 UTC