Best way to get ID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cczernia
Forum Newbie
Posts: 20
Joined: Tue May 16, 2006 2:00 pm
Location: San Diego, CA

Best way to get ID

Post by cczernia »

I'm writing a program the INSERTS some data into an sql table(1). The table(1) has an ID that is key and autoincrements. I then want to INSERT some more data into another table(2) that has the same ID as table(1).

I'm not really sure how to do this. I could run a SELECT query but I normally use the ID and at that point I don't know what the ID is. How do I find out what the ID is for a record I've just inserted?

Thanks in advance.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Best way to get ID

Post by Zoxive »

There are built in functions for this.

Code: Select all

mysql_insert_id(); //mysql
 
$mysqli->insert_id; //mysqli
// or
mysqli_insert_id($Link);
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: Best way to get ID

Post by kryles »

http://ca3.php.net/mysql

lists mysql functions and short description
Post Reply