I want to check if a database exists or not using PDO only(if available). Also, if it's not possible, please provide me a quick solution on how to check database existence using if else statement. Any help is appreciated. Thank You!
Here's what I have done so far:
try {
$conn = new PDO("mysql:host=localhost", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Now since I have been connected, I want to check DB existence.
if(DB exists)
{
//check table existence
}
else {
//Create DB
}
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}