test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8" />
<title>test</title>
<script language="javascript">
function $(id){
return document.getElementById(id) ;
}
function get_get(){
var xmlhttp ;
var host = $("host").value ;
var user = $("user").value ;
var password = $("password").value ;
if(window.XMLHttpRequest){
//for firefox , sarafi , opera , chrome , IE7+
xmlhttp = new XMLHttpRequest() ;
}
else{
//for IE5 , IE6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") ;
}
var url = "test.php?host=" + host + "&user=" + user + "&password=" + password ;
xmlhttp.open("GET" , url , false) ; //or true
/*
Async = true mode
xmlhttp.onreadystatechange = function (){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
$("test").innerHTML = xmlhttp.responseText ;
}
}
*/
xmlhttp.send() ;
//Async = false mode
$("test").innerHTML = xmlhttp.responseText ;
}
function get_post(){
var xmlhttp ;
var host = $("host").value ;
var user = $("user").value ;
var password = $("password").value ;
var url = "test.php" ;
var send_value = "host=" + host + "&user=" + user + "&password=" + password ;
if(window.XMLHttpRequest){
//for firefox , IE7+ , sarafi , chrome , opera
xmlhttp = new XMLHttpRequest() ;
}
else{
//for IE5 , IE6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") ;
}
xmlhttp.open("POST" , url , false ) ;//or true
xmlhttp.setRequestHeader("content-type" , "application/x-www-form-urlencoded") ;
/*
//Async = true mode
xmlhttp.onreadystatechange = function (){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
$("test").innerHTML = xmlhttp.responseText ;
}
}
*/
xmlhttp.send(send_value) ;
//Async = false mode
$("test").innerHTML = xmlhttp.responseText ;
}
</script>
<style type="text/css">
#host{
border:1px solid #000;margin:0px 0px 0px 70px;
}
#user{
border:1px solid #000;margin:0px 0px 0px 60px;
}
#password{
border:1px solid #000;margin:0px 0px 0px 19px;
}
#get_test{
border:1px solid #000;border:1px solid #0000;cursor:pointer;
}
</style>
</head>
<body>
<span>Mysql Host:</span><input type="text" name="host" id="host" />
<br /><br />
<span>MySQL User:</span><input type="text" name="user" id="user" />
<br /><br />
<span>MySQL Password:</span><input type="password" name="password" id="password" />
<br /><br />
<span>Test MySQL Connect:</span> <input type="button" value="test" id="get_test"
οnclick="get_post()" />
<br /><br />
<span>Test Result:</span> <span id="test"></span>
</body>
</html>
test.php
<?php
error_reporting(0) ;
//test mysql connect
function test_connect($host , $user , $password){
$mysqli = new mysqli($host , $user , $password) ;
$html ;
if($mysqli->connect_error){
$html = "Can not connect to MySQL" ;
}
else{
$html = "Connect successful" ;
}
return $html ;
}
$host = $_GET['host'] ; //get mysql host
$user = $_GET['user'] ; //get mysql user
$password = $_GET['password'] ; //get mysql password
$host = $_POST['host'] ;
$user = $_POST['user'] ;
$password = $_POST['password'] ;
$test_html = test_connect($host , $user , $password) ;
echo $test_html ;
?>