Accessing MySQL database from another server

Say a friend has a MySQL database and agrees to let me access it from my server. I want to have my own set of PHP files, but use his database’s data

Shouldn’t this be possible?

In my trial, I think the MySQL access info is correct – ie. I just changed the host_name to the actual “http:” prefixed URL, nothing else should change. What about db_user?

Any ideas or directions to resources that might help?

Here’s what I’ve done so far:

  1. My friend set up a MySQL database on his webhost
  2. Then he sent me a page written in PHP that has the ‘login’ info for his MySQL database
  3. When I try to view the PHP page, the error I get isWarning: mysql_connect(): Access denied for user: '______@scgue.dreamhost.com' (Using password: ...

scgue.dreamhost.com is just for this example.

So it seems that my domain name is being appended to the MySQL user login name. So naturally, it will fail when trying to access my friend’s mysql account.

  1. Can I work around this? I’ve tried forcing my friend’s domain on the login, but no dice
  2. Is there another way for PHP to access a remote MySQL database?

Have you double-checked the user-name, password, and location by logging in directly and not through a PHP script?

Yes.

What we want to do is have two distinct front-ends, that access the same database.

My friend, “M”, has a working PHP script that accesses a MySQL database in Chicago. I would like my server, “A”, to have my own set of files here in Taipei. M can design his pages any way he likes, and i can design A anyway I like. But the underlying data is the same.

Maybe the “http://” is the problem. It doesn’t seem necessary. Also, do you perhaps need a port number?

$hostname = "mysql.snake.net:3307"; if (!($conn_id = @mysql_connect ($hostname, "cbuser", "cbpass"))) die ("Cannot connect to server\n");

You also might want to investigate whether there’s a performance difference between mysql_connect() and mysql_pconnect(), with the latter not closing the connection at the end of the script.

Mysql pages on mysql_connect and mysql_pconnnect.

Sorry not to be of more help. I’m a bit new to this.

Here is a text about permission problems (though a slightly different setup) when accessing remote databases. One day I will need to do this too… :s

If you are going to connect directly to his MySQL database, just have him set to allow from your IP address, instead of domain name.

You might want to look into database replication which is included in MySQL.