In my PHP/MySQL application I have the following query to insert data in a table:
INSERT INTO `my_table` VALUES ('','$value1','$value2').
Where the first value is an auto incremented primary key.
Now, what I want to do is that immediately after this insert operation, I want to enter some data in another table my_table2
where the primary key
of the entry in my_table
serves as foreign key
.
Should I use a trigger or is there some way to get the primary key of last entry of a table. Please answer with required code.
I am using mysqli and would like to keep this particular processing on database side.