$data = array()
$db_name_php = 'books'
if (!mysql_connect('localhost', 'root', '123456')) {
echo '不能连接到mysql'
exit
}
$result = mysql_query('show databases')
While($row = mysql_fetch_assoc($result)){
$data[] = $row['Database']
}
unset($result, $row)
mysql_close()
print_r($data)
echo '<br><br>' if (in_array(strtolower($db_name_php), $data))
echo '[',$db_name_php,']数据库存在'
else
echo '[',$db_name_php,']数据库不存在'
?>
<?php$con = mysql_connect("localhost", "hello", "321")
if (!$con)
{
die('Could not connect: ' . mysql_error())
}
$db_selected = mysql_select_db("test_db", $con)
if (!$db_selected)
{
die ("Can\'t use test_db : " . mysql_error())
}
mysql_close($con)
?>
其实就是先登录再选择数据库
mysql_select_db
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)