Jump to content

[SOLVED] php database multiple connection problem


shadiadiph

Recommended Posts

I am having problems with using two different config files to connect to different databases.

 

I have two sites that need the same updates all the time so i thought i could just do it from the one site and automatically update bot sites with the click of a button.

 

Problem is it is only updating the external site but if i change the two include files around it reverses the result and updates the internal site.

 

include("../../../site/connection.php");
include("../../../site2/connection.php");

 

both of the above link to databases

 

I then have my insert sql which works fine no need to post it on both connection files i have names the variables differently any ideas?

 

<?php
$db_host="localhost";
$db_name="sitedbname";
$dbusername="sitedbuser";
$dbpassword="sitedbpass";
$db_con=mysql_connect($db_host,$dbusername,$dbpassword);
$connection_string=mysql_select_db($db_name);
?>

<?php
$db_host2="www.site2.com";
$db_name2="site2dbname";
$dbusername2="site2dbuser";
$dbpassword2="site2dbpass";
$db_con2=mysql_connect($db_host2,$dbusername2,$dbpassword2);
$connection_string2=mysql_select_db($db_name2);
?>

 

 

looks like we need to see the insert code - there is nothing wrong with what you have there (except you are repeating yourself!)

 

Without seeing the other code its clear you have something that is either not executing the transaction twice OR you are not changing the db connection resource identifier when making the second.

 

If you have 2 sites doing the same thing - why are you using 2 databases? if they need to be identical then its MUCH easier to use (and have to administer) just the one database and let both sites connect to it.

unfortunately you are correct one database would be easier but I am updating for two different clients.

 

$insertsql ="insert into tblnewsdetails (headline, article, newsdate, sent) values ('$headline', '$article', now(), 'No' )";
$resultinsertsql=mysql_query($insertsql);

mm think i have it.

 

I got it working for adding but deleting i have yet to test yet I have to get both my databases back on track as the id keys are all out of sync with so many wrong inserts.

 

$resultinsertsql=mysql_query($insertsql,$db_con);
$resultinsertsql=mysql_query($insertsql,$db_con2);

 

is what seems to work

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.