<?php // Linux Box DEFINE('HOST', '192.99.11.136'); DEFINE('USRNM', 'f1874_test'); DEFINE('PSWD', '22665139'); DEFINE('DBNM', 'f1874_test'); $link = mysql_connect('192.99.11.136', 'f1874_test', ''); if (!$link) { die('cannot connect : ' . mysql_error()); } echo 'Connected'; $db_selected = mysql_select_db('f1874_test', $link); if (!$db_selected) { die ('cant select the database : ' . mysql_error()); } ?>
[13-Jun-2016 11:34:49 America/Chicago] PHP Warning: mysql_connect(): Connection timed out in /home/firstgam/public_html/cp/global/class/SQL.php on line 12
Код:
<?php // Linux Box DEFINE('HOST', '192.99.11.136'); DEFINE('USRNM', 'f1874_test'); DEFINE('PSWD', '22665139'); DEFINE('DBNM', 'f1874_test'); $link = mysql_connect('192.99.11.136', 'f1874_test', ''); if (!$link) { die('cannot connect : ' . mysql_error()); } echo 'Connected'; $db_selected = mysql_select_db('f1874_test', $link); if (!$db_selected) { die ('cant select the database : ' . mysql_error()); } ?> |
DEFINE('HOST', '192.99.11.136'); |
DEFINE('HOST', 'localhost'); |
$link = mysql_connect('192.99.11.136', 'f1874_test', ''); |
$link = mysql_connect('localhost', 'f1874_test', ''); |
DEFINE('HOST', '192.99.11.136'); DEFINE('USRNM', 'f1874_test'); DEFINE('PSWD', '22665139'); DEFINE('DBNM', 'f1874_test'); DEFINE('PORT', ''); $link = new mysqli(HOST, USRNM, PSWD, DBNM, PORT); if ($link->connect_error) { die('Error Connection (' . $link->connect_errno . ') ' . $link->connect_error); } $example = $link->query("SELECT * FROM `users` WHERE `userid` = '1' LIMIT 0, 1"); $result = $example->fetch_assoc(); echo $result['username']; $link->close(); |
i got same your problem when i have a linux host
i don't know why MySQL hosted in a linux can be connected only with localhost if you want to make it working search for a windows hosting or search for a host support MySQL + Web Hosting For me, i sloved this problem by registering in this website mywindowshosting.com this website giving free web hosting windows for 2 months. when you register create a database and save the info of host |
mysql is no longer supported, use mysqli
And it is possible that the connection is closed from the outside |
This has nothing to do with the OS. Server providers and VPS users alike usually block remote connections from a security point of view. Only the essential ports are opened and the rest are securely closed. Admittedly, if you have a VPS you can whitelist certain IP addresses/ranges, while implicitly blacklisting all the rest.
And a word of caution: the "mysql" PHP extension is deprecated and has been completely removed from PHP 7 onwards. Use PDO or mysqli instead. |