Example PHP Web Service Return Selection Result (1)

It well time that I can create web service. I have my database and want to select data return result. How I do ?
I create 2 file service.php and callservice.php in service.php contain 2 function .
First function query data from database

function searchPatient($word)
{
$hostname_hciss = “localhost”;
$database_hciss = “hciss”;
$username_hciss = “root”;
$password_hciss = “”;
$hciss = mysql_pconnect($hostname_hciss, $username_hciss, $password_hciss) or trigger_error(mysql_error(),E_USER_ERROR);

if (!$hciss)
{
die(’Could not connect: ‘ . mysql_error());
}

mysql_select_db($database_hciss, $hciss);

$sql = “SELECT P_CODE, id_Card, fNAME, lNAME FROM person WHERE P_CODE LIKE ‘%”.$word.”%’ OR id_Card LIKE ‘%”.$word.”%’ OR fNAME LIKE ‘%”.$word.”%’ OR lNAME LIKE ‘%”.$word.”%’”;

$result = mysql_query($sql, $hciss) or die(mysql_error());

mysql_close($hciss);

return $result;
}

Second Function call searchPatient() and create table to return

function search($keyword)
{
$resultSearch = searchPatient($keyword);
$codeResult = "

P CODE ID FIRST NAME LAST NAME
“.$row[’P_CODE’].” “.$row[’id_Card’].” “.$row[’fNAME’].” “.$row[’lNAME’].”

“;
//return result in datarow
return $codeResult;
}

This complete file service.php

require_once(’lib\nusoap.php’);
$server = new soap_server;
$server->register(’search’, // method name
array(’keyword’ => ‘xsd:string’), // input parameters
array(’return’ => ‘xsd:string’), // output parameters
‘urn:hcissSearch’, // namespace
‘urn:hellowsdl#hcissSearch’, // soapaction
‘rpc’, // style
‘encoded’, // use
‘Return table of search result’); // documentation

function searchPatient($word)
{
$hostname_hciss = “localhost”;
$database_hciss = “hciss”;
$username_hciss = “root”;
$password_hciss = “”;
$hciss = mysql_pconnect($hostname_hciss, $username_hciss, $password_hciss) or trigger_error(mysql_error(),E_USER_ERROR);

if (!$hciss)
{
die(’Could not connect: ‘ . mysql_error());
}

mysql_select_db($database_hciss, $hciss);

$sql = “SELECT P_CODE, id_Card, fNAME, lNAME FROM person WHERE P_CODE LIKE ‘%”.$word.”%’ OR id_Card LIKE ‘%”.$word.”%’ OR fNAME LIKE ‘%”.$word.”%’ OR lNAME LIKE ‘%”.$word.”%’”;

$result = mysql_query($sql, $hciss) or die(mysql_error());

mysql_close($hciss);

return $result;
}

function search($keyword)
{
$resultSearch = searchPatient($keyword);
$codeResult = ”

P CODE ID FIRST NAME LAST NAME
“.$row[’P_CODE’].” “.$row[’id_Card’].” “.$row[’fNAME’].” “.$row[’lNAME’].”

“;
//return result in datarow
return $codeResult;
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ”;
$server->service($HTTP_RAW_POST_DATA);
?>

net to callservice.php

One Response to “Example PHP Web Service Return Selection Result (1)”

  1. Example PHP Web Service Return Selection Result (2) | ITBeginner Says:

    […] Grid (HPC) « Example PHP Web Service Return Selection Result (1) […]

Leave a Reply