Jump to content

[SOLVED] Input to two databases


aztec

Recommended Posts

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

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.