【发布时间】:2013-05-08 12:38:54
【问题描述】:
我有一个 Apache 服务器,它连接到 MySQL 数据库服务器。我收到很多错误消息:
PHP 警告:mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on '10.0.0.13'
但大多数时候,连接没有问题,我可以telnet 10.0.0.13 3306 没有问题。如何找出问题所在?
源码是php脚本,大部分时间运行没有任何问题。这是我的连接方式:
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors','On');
date_default_timezone_set ('Europe/Copenhagen');
Header('Content-type: text/xml');
$conn = new mysqli('10.0.0.13','webuser', 'xxxxxx', "np_indexes");
有什么建议吗?
此连接是否正确关闭?
$sql = "call spGetOrderDepthBySymbol('$stock', 0)";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) { ?>
<row>
<type static="true"></type>
<shares flash="true"><?= $row['shares']<>"" ? number_format($row['shares'], 0, ',', '.') : '-' ?></shares>
<price flash="true"><?= $row['price']<>"" ? number_format($row['price'], 2, ',', '.') : '-' ?></price>
</row>
<? }
?>
<spacer static="true"></spacer>
<?
$conn->next_result();
$sql = "call spGetOrderDepthBySymbol('$stock', 1)";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) { ?>
<row>
<type static="true"></type>
<shares flash="true"><?= $row['shares']<>"" ? number_format($row['shares'], 0, ',', '.') : '-' ?></shares>
<price flash="true"><?= $row['price']<>"" ? number_format($row['price'], 2, ',', '.') : '-' ?></price>
</row>
<? }
mysql_close($result);
?>
【问题讨论】:
-
你的mysql运行了吗?也许重启 mysqld 服务?
-
可能存在连接限制。
-
您记得在完成连接后关闭连接吗?即使(尤其是)您的程序提前出错?
-
MySQL 正在运行,99% 的时间都没有问题。重启不能解决这个问题,我试过了。我在哪里可以检查是否有连接限制?
-
这可能是因为连接没有正确关闭。我关闭这个正确吗?在原始帖子中添加了一个脚本。