在nginx的html下,创建一个测试的.php文件,往里面写入内容并用浏览器访问相应页面,输入数据库用户和密码提示 OK-数据库连接成功表示php连接数据库成功。
<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 header("content-type:text/html;charset=utf-8"); 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—数据库连接成功!"; } } ?>