1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <?php
require('nusoap-0.7.2/lib/nusoap.php');
$s = new soap_server;
$s -> register('people_select');
echo $s
function people_select($user, $pwd, $id)
{
if($user != "myuser" || $pwd != "mypwd") // Checks username/password
return new soap_fault("Client", "Login incorrect", "Bad value of params 'user' or 'pwd'");
if(empty($id))
return new soap_fault("Client", "Bad request", "'id' can't be empty");
$query = "SELECT name, age, city FROM people WHERE id = $id";
if(($conn = @mysql_connect("localhost", "root", "")) === FALSE)
return new soap_fault("Server", "MySQL", mysql_error());
if((@mysql_select_db("test", $conn)) === FALSE)
return new soap_fault("Server", "MySQL", mysql_error());
$res = @mysql_query($query, $conn);
if(mysql_num_rows($res) < 1) // Checks whether there are results
return new soap_fault("Server", "MySQL", "No results");
@mysql_close($conn);
/* Sends the results to the client */
$resp = @mysql_fetch_array($res, MYSQL_ASSOC);
$resp["time"] = time();
return $resp;
}
$s -> service($HTTP_RAW_POST_DATA); // Executes the RPC
?> |
Partager