重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
?php
资溪ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
$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
?php
$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 'brbr'; if (in_array(strtolower($db_name_php), $data))
echo '[',$db_name_php,']数据库存在';
else
echo '[',$db_name_php,']数据库不存在';
?
form action="" method="post"
select name="host"
option value="localhost" selectedlocalhost/option
option value="127.0.0.1"127.0.0.1/option
/select
brbr
user:input type="text" name="user" value=""brbr
pwd :input type="passWord" name="pwd" value=""brbr
input type="submit" value="connent"
input type="reset" value="reset"
/form
?php
error_reporting(~E_ALL);
$host = $_POST['host'];
$user = $_POST['user'];
$pwd = $_POST['pwd'];
if(isset($_POST['host']) isset($_POST['user']) isset($_POST['pwd'])){
if(strlen($host)1 or strlen($user)1 or strlen($pwd)1){
echo "请完善相关数据库链接信息。";
exit(0);
}
$conn = mysql_connect($host, $user, $pwd) or die("Error-数据库连接失败!");
if($conn){
echo "OK—数据库连接成功!";
}
}
?