<?php
$username = $_post["username"];/* client request mode is POST, request parameters encapsulated into NSData type in httpbody to the server, the server in the PHP script language to receive the request parameters, Find data in the server based on parameters returned to the client */
$password = $_post["password"];
$type = $_post["type"];
/* Link Database 127.0.0.1 is loopback address, network software test, and Local machine interprocess communication */
$link = mysql_connect ("127.0.0.1", "root", "Nilaiba");/* Establish database connection (host address, user name, password) */
if ($link) {/* If database connection Cheng ' gong*/
/* Select the specified database */
if (mysql_select_db ("Duke", $link)) {
/* Define an array, save the results */
$results = Array ();
if ($type = = "Login") {
$selecSQL = "Select password from UserInfo where user_name = ' $username '";
$result = mysql_query ($selecSQL);
$row = Mysql_fetch_array ($result);
if ($row ["password"] = = $password) {
$results ["status"] = "success";
} else {
$results ["status"] = "Failed";
}
Echo (Json_encode ($results));//data returned by the server to the client
} else {
$insertSQL = "INSERT into userInfo values (' $username ', ' $password ')";
$result = mysql_query ($insertSQL);
$row = Mysql_fetch_array ($result);
Echo (Json_encode ($row));//data returned by the server to the client
}
}
}
?>
Simple server program written in PHP scripting language