我有一个Apache服务器,连接到MySQL数据库服务器。我得到了很多错误信息说:MySQL随机无法连接消息
PHP的警告:mysqli的:: mysqli的()(HY000/2003):无法连接到MySQL服务器上'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服务? – phpisuber01 2013-05-08 12:46:24
可能存在连接限制。 – 2013-05-08 12:47:36
您是否记得在完成后关闭连接?即使(特别是)当你的程序错误提前? – 2013-05-08 12:49:03