因此,当我尝试远程连接到我的数据库时,我不断收到此错误。奇怪的是它适用于一分钟1/2的查询,但在那些查询后它停止工作并给出此错误消息。这种情况刚刚开始随机发生,之前它曾经在每秒许多查询中正常工作。
详细说明:
任何想法可能会发生什么?
代码示例(这是我用来测试连接的代码):
$connection = mysql_connect('IP', 'DATABASE PASSWORD', 'PASSWORD', 'DATABSE NAME') or die(mysql_error());
if (!$connection)
die('Not connected : ' . mysql_error());
$db_selected = mysql_select_db('DATABSE NAME', $connection);
if (!$db_selected)
die ('Can\'t use : ' . mysql_error());
$string = mysql_query("SELECT * FROM `characters` WHERE `name` LIKE 'gil'") or die(mysql_error());
if($result = mysql_fetch_assoc($string))
echo $result['name'];
完整错误代码:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'IP' (4) in /vhosts/DOMAIN/httpdocs/test.php on line 1
Can't connect to MySQL server on 'IP' (4)
答案 0 :(得分:2)
您正在为mysql_connect
指定错误的参数:
mysql_connect('IP', 'DATABASE PASSWORD', 'PASSWORD', 'DATABSE NAME')
应该是:
mysql_connect('server address', 'user name', 'password')