I have 3 table with structure like this,
employee > id (PK), name
family > family_id (PK), id (employee PK)
father > father_id (PK), family_id (family PK), father_name
I know I can get the last inserted id using mysql_insert_id()
or LAST_INSERT_ID
, and I wanted to get the ID and insert it to each table like this:
INSERT INTO employee VALUES('', '<value>')
//
//
INSERT INTO family VALUES('', '".mysql_insert_id()."')
// id from employee PK
//
INSERT INTO father VALUES('', '".mysql_insert_id()"', '')
// id from family PK
Am I doing the right thing? If yes, is there any better way to do the exact same thing?
Thank you. :)