Forum Moderators: coopster

Message Too Old, No Replies

Linking between hosts

         

c2web

10:16 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



Can someone please let me know if it is possible to link a website hosted with one hosting company - with a MySQL database set up for another.

To cut short I have a website I have had in operation for many years but tied down to a contract I can not change. I want to add the functionality of a MySQL database, but they do not support this.

I have other websites on different hosts that do have spare MySQL databases and was wondering whether I can cross-link?

Hope this makes sense?
D

lobo235

10:23 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



It depends on how the MySQL host is setup. Many hosts will not allow outside access to the mysql server. Also, the host without a mysql server may have a firewall that prevents access to certain ports etc. Give it a try and see what happens but I am doubtful that you will be able to access it. I had a situation like this once and I had to write some PHP scripts that would queries from the host without mysql to the host with mysql so they could be executed. If there was a SELECT query then I would echo the results out to the page, etc. It was a pain but it worked for a while until I could get things figured out.

mcibor

10:33 pm on Aug 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Theoretically yes, you can do that. However it's unsafe, insecure, slow and uses bandwidth.

However if you're still determined here's what you do:
On nodb.server.com write you script
on mysql.server.com write a script to process a db and echo info.

You can call a script on mysql.server.com with include. But remember - it will only echo things, no variables returned!

So nodb: include("mysql.server.com/update.php?id=2&money=200&user=root");

And on mysql.../update.php you will have:

<?php
if(!($id = (int)$_GET["id"])) die("Wrong id");
$money = (int)$_GET["money"];
if(ctype_alnum($_GET["user"]) $user = $_GET["user"];
else die("Username must be only alphanumeric");

$sql = "UPDATE table SET money='money' WHERE id='$id' AND user='$user'"
mysql_query($sql) or die("Error: ".mysql_error());
echo "The amount of money was submitted";?>


Hope this helps
Michal CIbor