I want the database to be created only if it does not exist. Now that the database exist, nothing happening but the following message is displayed anyway: Database created successfully. I would like this message to be displayed only when the database is created and not when it already exists. How to check if a database exists? This is my code.
<?php
 
    $mysql = @mysqli_connect("localhost", "test", "test"); 
    if(!($mysql)) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        exit();
      }
    $myDB = "CREATE DATABASE IF NOT EXISTS myDB";
    if ((mysqli_query($mysql, $myDB))) {
        echo "Database created successfully";
      } else {
        echo "Error creating database: " . mysqli_error($mysql);
      }
      mysqli_close($mysql); 
    ?>
 
     
    