cyberfly
cyberfly

Reputation: 5858

How to use multiple database on different host using php?

I have this array that store the connection info and i want to use it when perform the query

$dblist = array();

$dblist[] = array(
        'host'=>'192.168.1.20',
        'username'=>'root',
        'password'=>'root1',
        'database'=>'unsubscribe_1',
        'table'=>'subscribers'
        );

$dblist[] = array(
        'host'=>'192.168.1.5',
        'username'=>'root',
        'password'=>'root2',
        'database'=>'unsubscribe_test',
        'table'=>'subscribers2'
        );


foreach($dblist as $list)
{
$host = $list['host'];
$username = $list['username'];
$password = $list['password'];
$db = $list['database'];
$tb = $list['table'];

$conn1 = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db,$conn1) or die(mysql_error());

$sql = "select * from $db";
$query = mysql_query($sql,$conn1) or die(mysql_error());    
}

The problem is i keep getting this error "Host '192.168.1.5' is not allowed to connect to this MySQL server"

What is the problem here?

Upvotes: 0

Views: 1368

Answers (1)

Michael
Michael

Reputation: 1322

I assume Host '192.168.1.5' is your local machine and you encounter this error when trying to connect to Host .20, You need to enable remote access for Host .5 on Host .20's MySQl server.

HowTo

-michael

Upvotes: 1

Related Questions