Can I connect two mysql database located in different server by php? I want to connect two mysql database from different server. Is it possible..

Please give me a example if yes. I have bluehost and godaddy server.
You can actually use as many connections as needed (within system resources limitations).

Using mySQLi:

&lt;?php
$servername_1 = "server_1";
$username_1 = "username_1";
$password_1 = "password:1";
$db_1 = "db_1" ;

$servername_2 = "server_2";
$username_2 = "username_2";
$password_2 = "password_2";
$db_2 = "db_2" ;

// Create connections, and check
$conn_1 = new mysqli($servername_1, $username_1, $password_1, $db_1);
if ($conn_1-&gt;connect_error) {
    die("Connection 1 failed: " . $conn_1-&gt;connect_error);
} 

$conn_2 = new mysqli($servername_2, $username_2, $password_2, $db_2);
if ($conn_2-&gt;connect_error) {
    die("Connection 2 failed: " . $conn_2-&gt;connect_error);
} 

echo "Connected successfully";
?&gt;


Using PDO

&lt;?php
$servername_1 = "server_1";
$username_1 = "username_1";
$password_1 = "password:1";
$db_1 = "db_1" ;

$servername_2 = "server_2";
$username_2 = "username_2";
$password_2 = "password_2";
$db_2 = "db_2 ;

try 
{
    $conn_1 = new PDO("mysql:host=$servername_1;dbname=$db_1", $username_1, $password_1);
    // set the PDO error mode to exception
    $conn_1-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully 1"; 
}
catch(PDOException $e)
{
    echo "Connection failed: " . $e-&gt;getMessage();
}

try 
{
    $conn_2 = new PDO("mysql:host=$servername_2;dbname=$db_2", $username_2, $password_2);
    // set the PDO error mode to exception
    $conn_2-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully 2"; 
}
catch(PDOException $e)
{
    echo "Connection failed: " . $e-&gt;getMessage();
}
?&gt;


More parameters can be passed both to the mysqli function (such as port number) or the PDO connection strings.

For more info:


PHP Connect to MySQL  (the above examples are basically a variation (x 2) of theirs)
MySQL Improved Extension
MySQL Functions (PDO_MYSQL)