php判斷數據庫是否連接成功的測試例子
如果出現數據庫配置不正確的錯誤,請看php與mysql的配置教程:
win7系統下如何配置php-Apache-mysql環境 http://www.cnblogs.com/myall/p/4744837.html
<form action="" method="post">
<select name="host">
<option value="localhost" selected>localhost</option>
<option value="127.0.0.1">127.0.0.1</option>
</select>
<br><br>
user:<input type="text" name="user" value=""><br><br>
pwd :<input type="password" name="pwd" value=""><br><br>
<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—數據庫連接成功!";
}
}
?>

