$host='XXX';
創(chuàng)新互聯(lián)公司是一家專業(yè)提供江孜企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、H5開發(fā)、小程序制作等業(yè)務(wù)。10年已為江孜眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。
$user='XX';
$pass='XXX';
$db='edu';
$conn=@mysql_connect($host,$user,$pass);
if(!$conn){
echo 'script alert("數(shù)據(jù)庫錯(cuò)誤");window.location.href="XX.php";/script';
}
else{
mysql_select_db($db,$conn);
}
mysql_query("SET NAMES UTF8");
?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);
?
其實(shí)就是先登錄再選擇數(shù)據(jù)庫
mysql_select_db
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 "請完善相關(guān)數(shù)據(jù)庫鏈接信息。";
exit(0);
}
$conn = mysql_connect($host, $user, $pwd) or die("Error-數(shù)據(jù)庫連接失?。?);
if($conn){
echo "OK—數(shù)據(jù)庫連接成功!";
}
}
?