How do I access another MySQL Database from another IP Address with PHP?

mysql, php

Solution

`mysql_connect()`

$resource = mysql_connect('other-server-address.com', 'username', 'password');

The first parameter is the mysql server address.

Server Param

The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost.

If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'. In SQL safe mode, this parameter is ignored and value 'localhost:3306' is always used.

Unless I'm misunderstanding... this setup is pretty common. Any trouble you're having might be related to the following:

- Firewall settings

- Grant access to the mysql user to connect from the other host

- my.ini settings not allowing outside connections

Some other related SO questions:

- Connecting to MySQL from other machines

- How do I enable external access to MySQL Server?

- php access to remote database

- How to make mysql accept connections externally

- Remote mysql connection

Problem

Ok, If you can answer this question, you deserve the nobel peace prize. Anyways, here's the situation. I'm using Slicehost dot net, and I have 2 slices (two different IPs). One slice is my mail server and the other is my normal website. I'm running Ubuntu (8.04 or 8.10, something like that, it shouldn't matter). What I'm trying to do is access the MySQL database on the Mail server from the other slice. I'm trying to do that with PHP. I really appreciate any help.

Original source

Related problems