d_barszczak Posted September 25, 2007 Share Posted September 25, 2007 Hi all, This is probably very simple but i can't for the life of me figure this out. I have an auto increment on one of my columns labled 'id' that i use as an unique id fro each of my records. Is there anyway when i insert a record into my database i can find out which 'id' has been given to it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/70675-mysql-query-help/ Share on other sites More sharing options...
fenway Posted September 25, 2007 Share Posted September 25, 2007 Yes, LAST_INSERT_ID(). Quote Link to comment https://forums.phpfreaks.com/topic/70675-mysql-query-help/#findComment-355243 Share on other sites More sharing options...
d_barszczak Posted September 25, 2007 Author Share Posted September 25, 2007 Thanks, cant find LAST_INSERT_ID() on php.net but this seems to do the same thing. mysql_insert_id() Is this the same function or am i not looking hard enough? Quote Link to comment https://forums.phpfreaks.com/topic/70675-mysql-query-help/#findComment-355249 Share on other sites More sharing options...
fenway Posted September 25, 2007 Share Posted September 25, 2007 the former is the mysql function, the latter is the php function. Quote Link to comment https://forums.phpfreaks.com/topic/70675-mysql-query-help/#findComment-355260 Share on other sites More sharing options...
d_barszczak Posted September 25, 2007 Author Share Posted September 25, 2007 Ok so here is an example of my query. I understand how i could use the php function but how would i iplement the mysql function. $query = "INSERT INTO (username, password, email, enabled) VALUES ('admin','pass','me@my.com','1'); "; Which would be the prefered method and why? Quote Link to comment https://forums.phpfreaks.com/topic/70675-mysql-query-help/#findComment-355265 Share on other sites More sharing options...
fenway Posted September 25, 2007 Share Posted September 25, 2007 They're exactly the same, the php function just wraps it. Quote Link to comment https://forums.phpfreaks.com/topic/70675-mysql-query-help/#findComment-355295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.