I got this problem, let's see if some one here can give me a hand with it.
I got a website hosted in a computer, with its own database, and I can access it from any computer using the domain pointing to it or its public address.
Using PHP I'm running a little script (on my website) that connects to another database and brings some information; the thing is that this other database is hosted in a computer within a VPN (using Hamachi) where the client doesn't have access but the server does.
If I connect from the server using
Mysql -h (IP_ADDRESS_ON_THE_VPN) -u user -p
It connects perfectly, so no firewall problem / connection problem.
But if I open the PHP script from a client, it says:
"SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. "
in other words: timeout...
Another test I made is connect the client to the VPN, and that way works perfectly!, strage... doesn't PHP run on the server? What't the best approach here?
Thanks for you time.
EDIT: @Martin Cup Here's some of the code I use to make the connection, I´m almost sure that there´s not a problem in the code since it works if I add the client to the network.
try{
$DB_CTE = new PDO('mysql:host='.$SRV.';port='.$PUERTO.';dbname='.$BASE,$USU,$PASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage() . '<br><br>HOST:'.$SRV.'<br><br>Data CNX:' . $SRV ."(".$BASE.")".$PUERTO;
exit;
}
$sql = 'SELECT * FROM ' .$BASE. '.xxx ORDER BY FEC_EMI LIMIT 10 ';
try{
$query = $DB_CTE->prepare($sql);;
$query->execute();
$list = $query->fetchAll();
$xxx = array();
foreach ($list as $rs) {
echo "VTA: ".$rs['ID_FCV']."T_T: ".$rs['T_T']."
";
}
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage() . '<br><br>SQL:' . $sql;
exit;
}
@Hackerman I have root access to the database, and all host are avalible 'root'@'%', I'm sure of it since connect to it from serval computers. What I want to do now is to publish some info from that computer in the web (connecting to that database), I also can't stablish one IP address per client since it will be public and I don't know how many and from where clients will be connecting. Hope this makes sense.