php - Errors connecting to MySQL database from alternate domain -
i have 2 domains on 2 separate servers, foo.com
, bar.com
.
i have website , mysql database setup on foo
want migrate bar
, bar
doesn't have mysql.
as solution, i'm moving files across leaving database on foo
, , connecting remotely.
i'm connecting so:
connect.php
$hostname = 'database.foo.com'; $username = 'username'; $password = 'password'; $dbname = 'database'; try { $dbh = new pdo("mysql:host=$hostname;dbname=$dbname", $username, $password); } catch(pdoexception $e){ echo($e->getmessage()); }
this works fine on foo.com
when migrate file bar.com
error:
sqlstate[hy000] [2003] can't connect mysql server on 'database.foo.com' (110)
i can have 2 sites, foo.com
, bar.com
open in 2 windows, , 1 work while other doesn't - despite fact both connecting (or trying connect) same database.
why happening , how can rectified?
the database server not configured listen on network port accessible other server.
there several reasons why might be.
it typical listen on local sockets , not use tcp/ip @ since more efficient , secure.
the port might firewalled off other machine.
the server might accessible on local network , foo.com
might different network no route bar.com
database.foo.com
.
Comments
Post a Comment