aztec Posted February 5, 2008 Share Posted February 5, 2008 Hello Is it possible using PHP to input the same data from a form into two databases when the submit button is clicked. I have a need to load information onto my web MYSQL database and at the same time load the information from the same form into my "localhost" MYSQL database. Both are identical databases i.e. both are v 5. same database name same table names. At the moment I dump from my local database and transfer the dump to the web database. I have used the same script to load into the local database and by changing the password etc. into the web datebase. I am using a combination of HTML; PHP, MYSQL and CSS on the input form. Kind Regards Quote Link to comment https://forums.phpfreaks.com/topic/89585-solved-input-to-two-databases/ Share on other sites More sharing options...
sKunKbad Posted February 5, 2008 Share Posted February 5, 2008 Once you have inserted the data to database #1, just close the connection, and open up a second connection to database #2. Quote Link to comment https://forums.phpfreaks.com/topic/89585-solved-input-to-two-databases/#findComment-458949 Share on other sites More sharing options...
aztec Posted February 5, 2008 Author Share Posted February 5, 2008 Thanks sKunKbad I never thought of that but it sounds too easy, I'll try it to see if it works Regards Quote Link to comment https://forums.phpfreaks.com/topic/89585-solved-input-to-two-databases/#findComment-458951 Share on other sites More sharing options...
rhodesa Posted February 5, 2008 Share Posted February 5, 2008 you can have several DB connections open at the same time, you just have to keep track of your connection resources... <?php //Connection 1 $cnx1 = mysql_connect('hostname','user','pass'); mysql_select_db('testdb',$cnx1); //Connection 2 $cnx2 = mysql_connect('localhost','user','pass'); mysql_select_db('testdb',$cnx2); $sql = "UPDATE table SET field = 'update me' WHERE id = 123"; mysql_query($sql,$cnx1); mysql_query($sql,$cnx2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89585-solved-input-to-two-databases/#findComment-458956 Share on other sites More sharing options...
aztec Posted February 5, 2008 Author Share Posted February 5, 2008 Hello rhodesa Many thanks, looks like a neat bit of code, I looks like it will do what need. When I get back to my computer I'll give it a try. Regards Quote Link to comment https://forums.phpfreaks.com/topic/89585-solved-input-to-two-databases/#findComment-458973 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.