Mudsaf Posted April 17, 2012 Share Posted April 17, 2012 Im wondering is it possible to make 2x connections in 1 page whitout getting error from other connection. (Whitout disabling errors on PHP.ini also.) My code so far this. <?php$local = mysql_connect('localhost', 'root', 'PASSWORD);if (!$local) {} else {mysql_select_db("DATABASE"); }$server = mysql_connect("HOSTSERVER", "USER", "PASS");if (!$server) {} else {mysql_select_db("DATABASE");}?> So my point is i want to create php that first tries to connect localhost, if it gets error and cannot connect it tries to connect to "HOSTSERVER". (Whitout getting errors on "Localhost" connection.) Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 17, 2012 Share Posted April 17, 2012 i dont think its possible but then again, it might be possible, have you try something like this <?phpinclude "mysql_connect.php";$server = mysql_connect("HOSTSERVER", "USER", "PASS");if (!$server) {} else {mysql_select_db("DATABASE");}?> then you add some select from to see if it works or make a test.php to see if it connects to both connection "thats my opinion on this, might be wrong tho" Link to comment Share on other sites More sharing options...
alvo Posted April 17, 2012 Share Posted April 17, 2012 "thats my opinion on this, might be wrong tho" I agree! ^^ Link to comment Share on other sites More sharing options...
Mudsaf Posted April 17, 2012 Author Share Posted April 17, 2012 Oh okay, ill just have to configure another connection page. Link to comment Share on other sites More sharing options...
birbal Posted April 17, 2012 Share Posted April 17, 2012 you can make as many conection simultanously as you want but you have to store it somewhere to use it later. you have to mention the connection to use each conection to the functions (mysql function) where conection param is optional. by default those param takes last opened conection. connecting on remote server is dependent on how the remote server has been set up. Link to comment Share on other sites More sharing options...
divinedesigns1 Posted April 18, 2012 Share Posted April 18, 2012 so i was partly right? Link to comment Share on other sites More sharing options...
Err Posted April 18, 2012 Share Posted April 18, 2012 <?php $local = @mysql_connect('localhost', 'root', 'PASSWORD'); if ($local) { mysql_select_db("DATABASE",$local); } else { $server = @mysql_connect('HOSTSERVER', 'USER', 'PASS'); if ($server) { mysql_select_db("DATABASE",$server); } else { echo "No connections were able to be established."; } }?> Try that code. It's not tested but it should do what you want. It's important to note that the @ in front of mysql_connect is to suppress errors. So just in case it doesn't connect the it won't give you any errors. Also if you want a certain connection to try to access a database you have to tell it which connection. mysql_select_db() has two arguments, the database name and the connection to use.e.g. mysql_select_db(DATABASE_NAME, MYSQL_CONNECT() ) Link to comment Share on other sites More sharing options...
birbal Posted April 18, 2012 Share Posted April 18, 2012 its best to avoid supressing oprator (@). if you dont want to show error in production server make php.ini setting not to display error. instead of that log those error. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.