When you are not able to connect to a database, it generates a warning and not a exception. So the execution does not go to catch statement as there is no exception occuring here. You should do it this way:
<?php
$con = mysqli_connect(
$host,
$username,
$password,
$database
);
if(!$con) {
$con = mysqli_connect(
$host,
$username,
$password
);
$q1 = "CREATE DATABASE $database";
mysqli_query($conE, $q1);
$con = mysqli_connect(
$host,
$username,
$password,
$database
);
}
$q2 = "CREATE TABLE product
(
ProductID int NOT NULL AUTO_INCREMENT,
ProductName varchar(500),
ProductDescription varchar(2000),
ProductPhotoLink varchar(200) NULL,
ProductPrice decimal(10,2),
ProductCategory varchar(300),
ProductStock int(100),
ProductDatePosted timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (ProductID)
)";
mysqli_query($con, $q2);
?>