pradeep79 Posted March 28, 2007 Share Posted March 28, 2007 Hi, I'm creating an application in PHP/MySQL. My problem is I need to create a user account in the DB and then put the primary key of the user, i.e the user ID into various tables as foreign key. How do I write the script? Do I first create the user record in the table and retrieve the ID and insert into other tables with PHP script? Or, could it be done in the database with stored procedures? Link to comment https://forums.phpfreaks.com/topic/44709-dynamic-db-record-creation/ Share on other sites More sharing options...
trq Posted March 28, 2007 Share Posted March 28, 2007 It would be much more efficient (if your db supports it) to look into triggers. Link to comment https://forums.phpfreaks.com/topic/44709-dynamic-db-record-creation/#findComment-217081 Share on other sites More sharing options...
Waldir Posted March 28, 2007 Share Posted March 28, 2007 INSERT INTO foo (auto,text)VALUES(NULL,'text'); INSERT INTO foo2 (id,text)VALUES(LAST_INSERT_ID(),'text'); Links for more info and comments: http://www.mysql.com/doc/en/Getting_unique_ID.html http://www.php.net/mysql_insert_id Link to comment https://forums.phpfreaks.com/topic/44709-dynamic-db-record-creation/#findComment-217086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.