shadiadiph Posted August 2, 2009 Share Posted August 2, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/168495-solved-php-database-multiple-connection-problem/ Share on other sites More sharing options...
ToonMariner Posted August 2, 2009 Share Posted August 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/168495-solved-php-database-multiple-connection-problem/#findComment-888836 Share on other sites More sharing options...
shadiadiph Posted August 2, 2009 Author Share Posted August 2, 2009 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); Link to comment https://forums.phpfreaks.com/topic/168495-solved-php-database-multiple-connection-problem/#findComment-888840 Share on other sites More sharing options...
trq Posted August 2, 2009 Share Posted August 2, 2009 mysql_query's second argument is your connection resource. You will need to execute mysqL_query twice, once for each connection. Link to comment https://forums.phpfreaks.com/topic/168495-solved-php-database-multiple-connection-problem/#findComment-888842 Share on other sites More sharing options...
shadiadiph Posted August 2, 2009 Author Share Posted August 2, 2009 mm i just tried that and it updated the same database twice Link to comment https://forums.phpfreaks.com/topic/168495-solved-php-database-multiple-connection-problem/#findComment-888843 Share on other sites More sharing options...
shadiadiph Posted August 2, 2009 Author Share Posted August 2, 2009 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 Link to comment https://forums.phpfreaks.com/topic/168495-solved-php-database-multiple-connection-problem/#findComment-888846 Share on other sites More sharing options...
shadiadiph Posted August 2, 2009 Author Share Posted August 2, 2009 i guess that is what you meant by second resource thorpe thanks but i didn't get it the first time Link to comment https://forums.phpfreaks.com/topic/168495-solved-php-database-multiple-connection-problem/#findComment-888850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.