I am using xampp, if that helps.
The code is supposed to send a query from the client.php to the server.php for a module name from the database and return corresponding module code and lecturer name. Sending the query and the DB query by itself work fine, however when the response reaches the client.php, the array returned is empty. Can anyone help please?
server.php
<?php // Pull in the NuSOAP code require_once('nusoap.php'); require_once('db_connect.php'); $con = new mysqli("localhost", "root", "", "experience"); // Check connection if ($con -> connect_errno) { echo "Failed to connect to MySQL: " . $con -> connect_error; exit(); } // Create the server instance $server = new soap_server(); // Initialize WSDL support $NAMESPACE = 'http://www.uom.ac.mu/experience'; $server->debug_flag=false; $server->configureWSDL('Module', $NAMESPACE); $server->wsdl->schemaTargetNamespace = $NAMESPACE; // ==== METHOD IMPLEMENTATION =============================================== // ---- getExperience(module) ------------------------------------------------------ function getExperience($value) { $searchCriteria = $value['input']; $sql = "SELECT CONCAT( L.Name, ' ', L.Surname ) AS Lecturer, CONCAT( M.ModuleCode, '-', M.ModuleName ) AS Module, L.Experience AS Experience FROM lecturers L, modules M WHERE L.ModuleCode = M.ModuleCode AND M.ModuleName LIKE '%".$searchCriteria."%' ORDER BY L.Experience DESC;"; //$result = mysql_query($sql); $result = mysqli_query($con, $sql); $experience = array(); $experienceArray = array(); if (mysqli_num_rows($result) > 0) { //if(mysql_num_rows($result) > 0){ //while ($row = mysql_fetch_assoc($result)) { while($row = mysqli_fetch_assoc($result)) { $experience = array('lecturer'=>$row['Lecturer'], 'module' => $row['Module'], 'experience' => $row['Experience']); $experienceArray[] += $experience; } //mysql_free_result($result); } else{ $module = array('lecturer'=>'NO DATA', 'module' => 'NO DATA', 'experience' => 'NO DATA'); } return $experienceArray; //mysql_close($con); mysqli_close($con); } // ==== WSDL TYPES DECLARATION ============================================== // ---- LecturerExperience ---------------------------------------------------------------- $server->wsdl->addComplexType( 'LecturerExperience', 'complexType', 'struct', 'sequence', '', array( 'lecturer' => array('name'=>'lecturer','type'=>'xsd:string'), 'module' => array('name'=>'module','type'=>'xsd:string'), 'experience' => array('name'=>'experience','type'=>'xsd:int') ) ); // ---- LecturerExperienceArray[] -------------------------------------------------------------- $server->wsdl->addComplexType( 'LecturerExperienceArray', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array( array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:LecturerExperience[]') ), 'tns:LecturerExperience' ); // ==== WSDL FUNCTIONS REGISTRATION =========================================== $server->register('getExperience', // method name array('input' => 'xsd:string'), // input parameters array('output' => 'tns:LecturerExperienceArray'), // output parameters $NAMESPACE); //namespace // ==== PROCESS REQUEST ===================================================== @$server->service(file_get_contents("php://input")); exit(); ?> client.php
<?php error_reporting(E_ALL); require_once('nusoap.php'); //Get input parameter if(isset($_GET["txt_module"])) $module = $_GET["txt_module"]; //Create a soap client $url = "https://localhost/xampp/Sem2/Week3/server.php?wsdl"; $client = new nusoap_client($url); $err = $client->getError(); if ($err) { echo '<p><b>Error: ' . $err . '</b></p>'; } $args = array('input' => $module); print_r($args); $response = $client->call('getExperience', array($args)); //Display SOAP Request/Response echo '<h2>Request</h2>'; echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; echo '<h2>Response</h2>'; echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>'; //Reading returned Object and creating XML $XMLDocument = new SimpleXMLElement('<?xml version="1.0" ?><Experiences></Experiences>'); foreach($response as $record){ $experience = $XMLDocument->addChild('LecturerExperience'); $experience->addChild('Lecturer',$record[lecturer]); $experience->addChild('Module',$record[module]); $experience->addChild('Experience',$record[experience]); } // Apply XSLT to display the SOAP Response $XSLDocument = new DOMDocument(); $XSLDocument->load("module.xsl"); $XSLProcessor = new XSLTProcessor();//PHP5 $XSLProcessor->importStylesheet($XSLDocument); echo $XSLProcessor->transformToXML($XMLDocument); ?>