SOAP web service using PHP + Mysql


This post for people those who are facing trouble with my last article “How to create SOAP service?”. These days web service is playing vital role in most of the web or mobile based application, where cross platform application used to connect and share data using web service. I will explain with some simple steps to do this stuff.


Step 1:

Create a server page called soap_server.php into http://localhost/soapserver/. Paste the below code into the soap_server.php file.

// nosoap.php library file inside your lib/ directory

$server = new nusoap_server;

//$server ->configureWSDL('server', 'urn:server');
//$server ->wsdl->schemaTargetNamespace = 'urn:server';
//$server ->register('pollServer', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server#pollServer');

//register a function that works on server

 // create age calculation function
 function find_age($birthday)
    list($byear, $bmonth, $bday) = explode('-', $birthday);
   list($cyear, $cmonth, $cday) = explode('-', date('Y-m-d'));
   $cday -= $bday;
   $cmonth -= $bmonth;
   $cyear -= $byear;
   if($cday < 0)
   if($cmonth < 0)
   return $cyear;

 // create the function 
 function getInfo($name, $birthday)
    $result['status'] = true;

      return new soap_fault('Client','','SANJAY!');

    // Return if you would like to check server response else delete this line.
    return $result = array('name'=> $name,'age'=> find_age($birthday) );


    $conn = mysql_connect('localhost','root','');
    mysql_select_db('webservice', $conn);

    $sql = "SELECT * FROM books";
    $q = mysql_query($sql);

    $result = array();

    while($row = mysql_fetch_array($q)) {

       $result[] = array(


   return $result;

$server ->service($HTTP_RAW_POST_DATA);

Step 2:

Now let us create a page called soap_client.php and paste below code to call soap server.

header('Content-type: text/html');

$client = new nusoap_client('http://localhost/soapserver/soap_server.php');
$err = $client->getError();

if ($err) {

 echo '

Constructor error

' . $err . '

'; } $param = array( 'name' => 'Sanjoy Dey','birthday'=>'1987-12-20'); $response = $client->call('getInfo',$param); var_dump($response); if($client->fault) { echo "FAULT: Code: (".$client->faultcode.") "; echo "String: ".$client->faultstring; } else { echo $response['name']."\n Age: ".$response['age']."'s"; } echo '<h2> Request</h2> <>' . htmlspecialchars($client-&gt;request, ENT_QUOTES) . '</br> '; echo '<h2> Response</h2> <br>' . htmlspecialchars($client-&gt;response, ENT_QUOTES) . '</br> '; //echo '<h2>Debug</h2><br>' . htmlspecialchars($client-&gt;debug_str, ENT_QUOTES) . '</br>';

Step 3:

Go to browser and run http://localhost/soapserver/soap_client.php file. You will Soap Response as "Name" and "Date of Birth".


This small post help you to create basic SOAP web service using PHP and nusoap.php library. Hope this post helps to solve displaying blank page. Keep visiting and stay updated. You can also join our technical groups by clicking below links.

Good Luck!

Follow Us On Facebook Open Source Web Developers by Appsntech facebook group Twitter Open Source Web Developers by Appsntech twitter group Google+ Open Source Web Developers by Appsntech Google group Linkedin Open Source Web Developers by Appsntech, LinkedIn group
Copyright @2011-2015 All rights reserved. Powered By- Sanjoy Dey Productions