dongliao2011 2013-05-10 03:46
浏览 28

在从中检索数据之前检查MySQL服务器是否正在运行[关闭]

What is the correct way of checking if the MySQL server is up and running before trying to retrieving data from it ?

I'm using PHP and MySQLI in the object orientated way.

I'm semi-new to MySQLI and managed to write something useful for my website. A voting system.

I have some code on my website that retrieves data from the MySQL server and displays it on the website.

This works fine as long at the MySQL server is up and running and are able to connect to it.

But if i turn off the MySQL server or otherwise my PHP code is not able to connect to the SQL server my website hangs for a while until timeout and then part of my website is not displayed.

  • 写回答

3条回答 默认 最新

  • dongzhunqiu4841 2013-05-10 03:51
    关注

    According to the mysqli documentation,

    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }
    

    I further suppose you could check the value of connect_errno to get a better idea of why the connection failed.

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法