[SOLVED] - How to get the auto generated ID just generated

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Are you sure you tried this in MySQL ?
By the way my MySQL ver is 4.0 and perhaps I thought that it'll be there in 4.1 or 5.0 like subselects (select within select which is supported only from 4.1) but there is nothing in the manual search.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yeah I have seen it in action before im sure however, that was in college and I was not entirly sure of the setup!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]mysql_insert_id[/php_man]() :?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Well thats another option feyd :D Something like:

Code: Select all

<?php
mysql_query("INSERT INTO Table1 VALUES ('',$Name)");
$ID= mysql_insert_id();
mysql_query("INSERT INTO Table2 VALUES ($ID,$Pass)");
?>
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Yes. But Im just afraid if there is a possibility that the last inserted id may not be actual last inserted id if some 100 users are adding the db at the same moment. The manual gives a lot of explanation to that but still..........not so sure[/pg_man]
Post Reply