Re: Getting the primary key from a MySQL insert
| From: | Andrew Wood | Date: | Fri, 16 Jul 2004 10:59:58 +0000 |
| Subject: | Re: Getting the primary key from a MySQL insert | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190695@lists.php.net to get a copy of this message | ||
Thanks. When it says 'the last insert' is that just the last insert my PHP script did, or the last insert on the DB as a whole?
On 16 Jul 2004, at 11:40, john@johnallsopp.co.uk wrote:
If the primary key in a MySQL DB is an autoincrementing integer, is there anyway of automatically getting it back when I do an insert in PHP. In other words taking the status returned by mysql_query and extracting the PK of the record we just entered?int mysql_insert_id ([resource link-id]) returns the key from the most recent INSERT statement or 0 if there's no auto-increment field. At last, a question I can answer :-) HTH J