Hey guys I want to be able to run queries to build up my database if mysqli returns error constant of 'ER_BAD_DB_ERROR'/1049. Here is my code. If the error is caught I don't want mysqli to display the error but rather just built the database.
What happens it that the unknown database error is display, error is caught in the if() statement and the database is built.
I realize mysqli if displaying the error because of this:
$connection = mysqli_connect($db_server, $db_user, $db_pwd, $dbname);
How do I just build the database in place of displaying the error if that exact error that I want is caught.
$db_server = "localhost";
$db_user = "user";
$db_pwd = "";
$dbname = "name";
#connect to database
$connection = mysqli_connect($db_server, $db_user, $db_pwd, $dbname);
#try to catch database not exist error
if ('ER_BAD_DB_ERROR') {
# if true build database and connect again
build_db();
$connection = mysqli_connect($db_server, $db_user, $db_pwd, $dbname);
} else {
#close connection with other errors encounter
die("database connection failed". mysqli_connect_error());
}
I'm not sure if I'm following best practices here. So, I'm wholeheartedly open to suggestions and feedback. Thanks Guys.
build_db()?