Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing ID of mysql insert during the insert

Tags:

php

mysql

Is there any way to access the id of the auto increment for use inside the query.

for instance Wordpress puts the id of the insert in the GUID of the same row, is there any way i can access the id that the row will take during the insertion.

Or maybe there is some quick way for me to find out what the current AI counter is at, so I know what the one going in will be?

I need this because I am trying to backfill the WP posts table into a new custom post type I am using, and I need to have the id of the insert to put inside the GUID column.

like image 357
Liam Bailey Avatar asked Jan 30 '11 20:01

Liam Bailey


1 Answers

Maybe the mysql LAST_INSERT_ID() function can help you. http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id

like image 102
ipsum Avatar answered Sep 28 '22 02:09

ipsum