This is a fairly basic question, I currently have two tables and in the second table there is a foreign key column for table A.
Table A:
id Name
----------------
1 Name1
2 Name2
Table B:
id Name Parent
-------------------------
1 John 1
What happens:
- My PHP script inserts
Name1into TableAand mysql inserts the id. - My PHP script needs to insert
Johninto TableBAND setParentto be theidof the query that was just inserted.
After the first insert, you can do:
Alternatively, you can use mysql_insert_id. However, from the manual:
Because of this, the first method I listed is preferred if your column uses — or may use in the future —
BIGINT.