Reputation: 65
I'm trying to design a database for my website but i have a little problem with making related tables .
I have two tables . Table1 and Table2
Table1 is used to store user`s information and Table2 is used to store their activation codes
To relate them i need to store each user's ID in Table1 , inside Each record of Table2 so that i can get my user`s activation code
And as i know it is how relational databases work.
My problem is when using php to run mysql commands and add new user information in Table1 , How can i find What ID Number will be assigned to my user so that i can save both Id and activation code in my other table ?
Upvotes: 0
Views: 33
Reputation: 338
If you use PDO, you can use the function lastInsertId()
to retrieve the last id inserted in your last query.
http://php.net/manual/en/pdo.lastinsertid.php
If you use Mysqli, you have the mysqli_insert_id()
function .
http://php.net/manual/en/mysqli.insert-id.php
Upvotes: 1