Bug #53152 [Com]: mysql_insert_id return 0
| From: | uramihsayibok at gmail dot com | Date: | Wed, 27 Oct 2010 01:05:47 +0000 |
| Subject: | Bug #53152 [Com]: mysql_insert_id return 0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155548@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53152&edit=1
ID: 53152
Comment by: uramihsayibok at gmail dot com
Reported by: genix at arctoz dot de
Summary: mysql_insert_id return 0
Status: Open
Type: Bug
Package: MySQL related
Operating System: Linux 2.6.34.6-54.fc13.i686
PHP Version: 5.3.3
Block user comment: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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