dongsheng8158 2013-05-08 12:38
浏览 54
已采纳

MySQL随机无法连接消息

I have an Apache server, that connects to a MySQL database server. I get a lot of error messages saying:

PHP Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on '10.0.0.13'

But most of the time, there's no problem connecting, and I am able to telnet 10.0.0.13 3306 without problems. How do I figure out what the problem is?

The source is php scripts, and most of the time it runs without any problem. Here is how I connect:

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");

Any suggestions?

Is this connection closed correct?

$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);
    ?>
  • 写回答

2条回答 默认 最新

  • dongtu0088 2013-05-08 13:02
    关注

    perhaps this is your case. see here

    the solution says:login as root and do setsebool -P httpd_can_network_connect=1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)