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...<
Please check this:
$servername='localhost';
$username='root';
$password='';
$databasename='MyDb';
$connection = mysqli_connect($servername,$username,$password);
if (!$connection) {
die("Connection failed: " . $conn->connect_error);
}
/*mysqli_query($connection, "DROP DATABASE if exists MyDb;");
if(!mysqli_query($connection, "CREATE DATABASE MyDb;")){
echo "Error creating database: " . $connection->error;
}
mysqli_query($connection, "use MyDb;");
mysqli_query($connection, "DROP TABLE if exists employee;");
$table="CREATE TABLE employee (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
$value="INSERT INTO employee (firstname,lastname,email) VALUES ('john', 'steve', 'johnsteve@yahoo.com')";
if(!mysqli_query($connection, $table)){echo "Error creating table: " . $connection->error;}
if(!mysqli_query($connection, $value)){echo "Error inserting values: " . $connection->error;}*/