retrieving data from remove server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
vinny199
Forum Newbie
Posts: 8
Joined: Sun Nov 16, 2003 12:58 pm
Location: London

retrieving data from remove server

Post by vinny199 »

Hi,

I am trying to do the following:

I would like 3 websites to "pull" data of the same MySql database on a 4th website / remote server.

How can I get my 3 websites to connect to that database on the 4th server in order to retrieve and display data from it?

The 4 sites are not hosted on the same server, hence a full path to the server in the connection string is not an option.

I can't see a way around it.

Can you help?

Thanks a lot,

vinny
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You could always have a small PHP page on the "4th server" which accesses the database, and then just use an include() or require() from the other websites to pull in the PHP file.

For example...

4th Server PHP

Code: Select all

<?php
mysql_connect("localhost", "X", "X");
mysql_select_db("myDatabase");
$result = mysql_query($sql);
?>
Other websites

Code: Select all

<?php

$sql = "SELECT * FROM `myTable`";
include("http://mySite.com/phpScript.php");

// Should now have a variable called $result which holds the result
// of the mysql query $sql

?>
It might work but I haven't tried it, it's just an idea.
You may need to change "localhost" in the mysql_connect() to your website address, something like "http://mySite.com".
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please don't cross-post, it is only necessary to post a topic once.

viewtopic.php?t=16678

Mac
Locked