0

I have a homepage (www.mywebsite.com) and a special server (sv1.mywebsite.com) for my website. They both have a different database. Now I would like to display on my homepage the number of users from sv1.mywebsite.com. I think it is not a good idea to disconnect the home database en connect the sv1 database, but what is the best option? Is it a good idea to create a xml file in the sv1 and read that data from the homepage?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jordy
  • 4,719
  • 11
  • 47
  • 81
  • You cannot use ajax here because of the same origin policy - have you thought about using PHP on www to connect to sv1 ? – Manse Nov 03 '11 at 13:05
  • Yes, but then I should disconnect the home database, connect to sv1 database, get data, disconnect sv1 database and again connect homedatabase. I think that there is a better way? – Jordy Nov 03 '11 at 13:06
  • Multiple connections : http://stackoverflow.com/questions/274892/how-do-you-connect-to-multiple-mysql-databases-on-a-single-webpage – Manse Nov 03 '11 at 13:09

1 Answers1

0

It heavily depends on the functionality that you need. Server-server communication is perfectly fine, and whether you use an encoded data format (xml or json) or connect dirrectly to the database -- doesn't matter.

Pros and cons for both: Opening database to be accessible from another server may be considered a security hole.

By the same token: having xml file available for download may be downloaded by people without using your website (may not be an issue in your case)

PHP can support multiple mysql communications as long as you keep track of the connection resource and pass it along with the rest of the queries.

Good luck


Edit: If you just want the end result, regardless of the approach -- you could create a simple php file on your sv1 that simply displays the number of users online, and have a tiny iframe on your main page.

Mikhail
  • 8,692
  • 8
  • 56
  • 82
  • Wow thanks. I searched for the php option to read XML data but I can't find it. Do you know a good guide? I found http://php.net/manual/en/function.file-get-contents.php but is that a good idea or should I use XML? – Jordy Nov 03 '11 at 13:27
  • I would strongly recommend JSON. But PHP has some [XML parsing tools](http://www.php.net/manual/en/function.xml-parse.php) too. I would also suggest using a DB class wrapper. That way you can create one object for server 1 and another object for server 2, and let the class handle the connection links. – Mikhail Nov 03 '11 at 14:09