?php
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專(zhuān)注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、小程序定制開(kāi)發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶(hù)創(chuàng)新互聯(lián)還提供了肅寧免費(fèi)建站歡迎大家使用!
$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ù)庫(kù)
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,']數(shù)據(jù)庫(kù)存在';
else
echo '[',$db_name_php,']數(shù)據(jù)庫(kù)不存在';
?
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 "請(qǐng)完善相關(guān)數(shù)據(jù)庫(kù)鏈接信息。";
exit(0);
}
$conn = mysql_connect($host, $user, $pwd) or die("Error-數(shù)據(jù)庫(kù)連接失?。?);
if($conn){
echo "OK—數(shù)據(jù)庫(kù)連接成功!";
}
}
?