Checking a database does exist or doesn't exist

I am using XAMPP on windows.

$dropDB=$dbc-> query("DROP DATABASE $myDB1");

I like to use the code above.
if there is the database “myDB1”, it drop the database.
so far so good.
however, if there is not the database “myDB1”. it produces fatal error saying like the following.

I don’t know whether $myDB1 does exist or doen’t exist.
I want if there is $myDB1, then drop it.

My wanna-be-code would look like the following.

if ( database $myDB1 exist ) {
$dropDB=$dbc-> query("DROP DATABASE $myDB");
}

How can I check whether a database does eist or doesn’t exist?

A quick search revealed the following query:

DROP DATABASE IF EXISTS database_name;

I should do the above, I am afraid, before I posted.
Thank you,

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.