Forum Moderators: coopster

Message Too Old, No Replies

mysql_connect

Acces a MySql database from a distant server

         

Polo75

8:40 am on Mar 23, 2005 (gmt 0)

10+ Year Member



Hi folks,

I own 2 sites on 2 different providers.
I wish a PHP script on one site access a database on the other site.

I used following instruction:
$link = mysql_connect("localhost", "mysql_user", "mysql_password")

But I do not know what to put for "localhost", and I even don't know if this could work.

Thanks for helping. Paul

timster

3:02 pm on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you'd probably put something like this, where $remote_database_address holds the mysql server's IP address or host name.

$link = mysql_connect($remote_database_address, "mysql_user", "mysql_password")

But you're right: this depends on whether your ISP allows access to their SQL databases from remote servers. It might be possible to do this with a secure tunnel, but again that depends on your ISP.

If all you need to do is display information from the database, you might have an easier time just including PHP pages from one site on the other.

volatilegx

3:23 pm on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My solution to this problem was to write PHP scripts to act as intermediaries. If one domain needed data that is stored on the other, domain sends a POST to a php script on domain 2, which queries the local database and responds to domain 1.

timster

4:44 pm on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



D'oh! In my last post I wrote "ISP" when I meant "web host."

I guess I'd better get more coffee.