MasterACE14 Posted April 10, 2009 Share Posted April 10, 2009 with my ads script, it doesn't work when I use it on my websites that connect to a different database. Like this... connect to database page content ads script (connects to ads database) rest of page content here's the ads connection script: <?php $conAdscon = mysql_connect("localhost",$mysql['user'],$mysql['pass']) or die(mysql_error()); $conAds = mysql_select_db("eliteace_client",$conAdscon); $AdsQuery = mysql_query("SELECT * FROM `c_ads` WHERE `active`='1'") or die(mysql_error()); while($AdsArr = mysql_fetch_array($AdsQuery)) { $ad[] = array($AdsArr['title'], $AdsArr['description'], $AdsArr['displayurl'], $AdsArr['url']); } mysql_close($conAdscon); ?> any suggestions? :-\ Regards, ACE Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 Define: doesn't work. What does it do or not do, what are the symptoms, errors, results? If the two databases are on the same database server, with the same hostname, user, and password, there is no need to create a new connection and in fact your code would be reusing the existing connection and the mysql_close() statement would be closing the connection that the rest of the page needs. Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/#findComment-806061 Share on other sites More sharing options...
MasterACE14 Posted April 10, 2009 Author Share Posted April 10, 2009 the connection details are the same, it's just the database that is different. $conAdscon = mysql_connect("localhost",$mysql['user'],$mysql['pass']) or die(mysql_error()); $conAds = mysql_select_db("eliteace_client",$conAdscon); // the website this ad script is going in uses eliteace_realmbattlesdev database Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/#findComment-806068 Share on other sites More sharing options...
MasterACE14 Posted April 10, 2009 Author Share Posted April 10, 2009 I guess if I can't do it this way, I could put the ads in a text file separate by a comma and explode each line to place the ad values in an array. Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/#findComment-806074 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. Your mysql_close() statement is closing the single link. Just select the correct database before the query and set it back to the main database after the query or specify the database in the query. Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/#findComment-806075 Share on other sites More sharing options...
MasterACE14 Posted April 10, 2009 Author Share Posted April 10, 2009 how would I specify the database in the query? that sounds like the way to go. Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/#findComment-806077 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 You can list db_name.tbl_name in place of the tbl_name in your query. Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/#findComment-806082 Share on other sites More sharing options...
MasterACE14 Posted April 10, 2009 Author Share Posted April 10, 2009 that worked! thank you Link to comment https://forums.phpfreaks.com/topic/153419-solved-multiple-database-connections/#findComment-806087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.