Monday, 20 March 2017

mysql - cross server access in php



Can I get data from three different servers on my php application? Actually I have my data on three different servers and I want to generate a report with having data from all three servers. Can you please suggest me a code for this?



 

function dbcon(ipaddress,servername,serverpassword,databasename)
{
$con = mysql_connect(ipaddress,servername,serverpassword);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db(databasename) or die ("Cant find DB");


}

Answer



Certainly that is possible. I assume (though you are not very clear in this) that you are talking about three database servers? Then all you have to do is:




  • make sure the database servers are accessible via network (tcp)

  • create three database connections instead of only one




Since opening a connection to a database server returns a handle you have something you can use to address a specific connection. The syntax required for opening the connection is clearly explained in the manual pages. I suggest you read them and take a look at the provided examples...


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...