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
https://forums.phpfreaks.com/topic/89585-solved-input-to-two-databases/
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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.