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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.