检查数据库连接,否则显示消息 [英] Check for database connection, otherwise display message

查看:78
本文介绍了检查数据库连接,否则显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查网站是否可以连接到mySQL.如果没有,我想显示一个错误,提示用户应在几分钟后尝试再次访问该页面...

I would like to check if the website can connect to mySQL. If not, I would like to display an error saying that the user should try to access the page again in a few minutes...

我真的不知道该怎么做;)

I really do not know how to do this ;)

任何帮助将不胜感激!

string mysql_error ([ resource $link_identifier ] )

但是我该如何使用呢?

这只是给我错误,但我希望消息显示有任何错误.

This just gives me the error, but I want the message to display with any error.

谢谢

推荐答案

尝试一下:

<?php
$servername   = "localhost";
$database = "database";
$username = "user";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}
  echo "Connected successfully";
?>

这篇关于检查数据库连接,否则显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆