This is for a sort of proof of concept draft to get things working, but don't want to have completely crap code. For my database, I tried to get true foreign key relations going using innoDB, but couldn't get it.
Instead of using foreign keys, I decided to just pull mysql_insert_id() after inserts, saving it as a variable, then putting that variable into the related table.
Is this horrible? Everything seems to work well, and I'm able to connect and relate ID's as needed. What benefits would using foreign keys give me over my method (besides updates/deletes cascading)?
mysql_query('INSERT INTO master...'); $master_id = mysqsl_insert_id(); mysql_query("INSERT INTO detail (master_id, ...) values ('$master_id', ...)");
. Then no, it's not horrible it's the only thing you can do to create the relation. The only other way is using "natural keys" or keys generated by your application but then the only difference is that you don't get the id withmysql_insert_id
but rather from the user. What exactly do you mean by foreign keys? – CouncillorADD CONSTRAINT 'mytable' FOREIGN KEY ('my_id') REFERENCES 'othertable' ('other_id') ON DELETE CASCADE ON UPDATE CASCADE;
– Lucianaluciano