Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I need to check whether the website can connect to MySQL. If not connecting, I want to display an error stating that the user should try to access the page again in some minutes...

I don't know how to do it.

Any kind of help would be appreciated!

string mysql_error ([ resource $link_identifier ] )

But how do I use this?

This simply gives me the error, however, I want to display the message with any error.

1 Answer

0 votes
by (12.7k points)

You can try this following code:

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

 Want to get certified in SQL? Join this SQL Training course by Intellipaat.

Related questions

0 votes
1 answer
asked Jan 1, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 30, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 29, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jan 7, 2021 in SQL by Appu (6.1k points)

Browse Categories

...