php判斷數(shù)據(jù)庫狀態(tài) php查詢數(shù)據(jù)是否存在

PHP代碼里怎么判斷數(shù)據(jù)庫是不是存在呢?

?php

資溪ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信: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);

?

其實就是先登錄再選擇數(shù)據(jù)庫

mysql_select_db

php怎么判斷數(shù)據(jù)庫數(shù)據(jù)是否存在

?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ù)庫存在';

else

echo '[',$db_name_php,']數(shù)據(jù)庫不存在';

?

php判斷數(shù)據(jù)庫是不是連接成功的測試例子

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 "請完善相關數(shù)據(jù)庫鏈接信息。";

exit(0);

}

$conn = mysql_connect($host, $user, $pwd) or die("Error-數(shù)據(jù)庫連接失?。?);

if($conn){

echo "OK—數(shù)據(jù)庫連接成功!";

}

}

?

分享題目:php判斷數(shù)據(jù)庫狀態(tài) php查詢數(shù)據(jù)是否存在
鏈接地址:http://muchs.cn/article0/doshooo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google企業(yè)網(wǎng)站制作、營銷型網(wǎng)站建設品牌網(wǎng)站建設、網(wǎng)站建設、品牌網(wǎng)站設計

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設