Erich Beyrent wrote:
Hi there,

I seem to be having a problem retrieving the last inserted ID for a
table.

The query I am using is as follows:

mysql> select distinct LAST_INSERT_ID() as LastID from listings;
+--------+
| LastID |
+--------+
|   3575 |
+--------+
1 row in set (0.00 sec)

However, when I run this from my PHP script, I get a value of 0.

Any clues as to how to resolve this?

  
LAST_INSERT_ID() works on the current connection.
Is it possible that you are inserting the record with one connection, and then selecting LAST_INSERT_ID() with another connection?
Also, there's no need to use 'distinct' - you will only ever get one record ( as far as I know ).
Actually, I don't think you need a 'from' clause either, ie it doesn't affect the result. You only ever get the *very* last inserted ID returned.

--
signature Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au
-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to