【发布时间】:2020-03-29 23:22:11
【问题描述】:
我想仅使用 PDO 检查数据库是否存在(如果可用)。此外,如果不可能,请提供一个快速解决方案,了解如何使用 if else 语句检查数据库是否存在。 任何帮助表示赞赏。谢谢!
这是我到目前为止所做的:
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();
}
【问题讨论】:
-
这能回答你的问题吗? How to check if mysql database exists
-