Home >Backend Development >PHP Tutorial >怎么判断MySQL里的某个数据库是否存在呢

怎么判断MySQL里的某个数据库是否存在呢

WBOY
WBOYOriginal
2016-06-13 09:58:381515browse

如何判断MySQL里的某个数据库是否存在呢?
以下代码失败~我想在有数据库的情况下不创建

$db=mysql_connect($_GET["MySQL_URL"],$_GET["db_User_Name"],$_GET["db_User_PW"]);
if(!$db)
{
die('连接数据库失败! '.mysql_error());
}
echo $_GET["Database_Name"];
$sql="if (db_id(/'".$_GET["Database_Name"]."/') is NULL ) CREAT DATABASE ".$_GET["Database_Name"];
if(mysql_query($sql,$db))
{
echo '数据库创建成功!';
}
else
{
echo '数据库创建失败! '.mysql_error();
}

------解决方案--------------------
mysql_select_db('foo', $lnk) or die ('Can\'t use foo : ' . mysql_error());

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn