Edit report at http://bugs.php.net/bug.php?id=53152&edit=1

 ID:                 53152
 Updated by:         ka...@php.net
 Reported by:        genix at arctoz dot de
 Summary:            mysql_insert_id return 0
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            MySQL related
 Operating System:   Linux 2.6.34.6-54.fc13.i686
 PHP Version:        5.3.3
 Block user comment: N
 Private report:     N

 New Comment:

.


Previous Comments:
------------------------------------------------------------------------
[2010-10-27 03:05:46] 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-10-25 18:50:23] 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


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53152&edit=1

Reply via email to