Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am learning php.

I have created Web Service in php using nusoap.dll. I have written price test method it's return integer it's working fine, but when I fetch database, to return array it's returning error. I had tried to resolve the error, but it's still giving error.

Could you tell me where I went wrong.

my php code is:

service.php

<?php

/**
 * @author 
 * @copyright 2013
 */

require 'lib/nusoap.php';
require 'functions.php';

$server = new nusoap_server();
$server -> configureWSDL('WS'.'urn:WS');
$server -> register(
                    "price", //name of the function
                    array("name" => 'xsd:string'), //inputs
                    array("return" => 'xsd:inter')  //outputs
                    );

$server -> register(
                    "ReadBooks", //name of the function
                    array("productid" => 'xsd:inter'), //inputs
                    array("return" => 'xsd:unbounded')  //outputs
                    );
                    
/**
 * $server -> register(
 *                     "countbooks", //name of the function
 *                     array(), //inputs
 *                     array()  //outputs
 *                     );
 */
                    
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

?>


functions.php

<?php

/**
 * @author 
 * @copyright 2013
 */

function price($name){
    
    $details=array('abc'=>100,
                   'xyz'=>200);
    foreach($details as $n => $p){
        if($name==$n){
            $prices = $p;
        }
    }
    return $prices;
}

function ReadBooks($productid)
{
    mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("Sample") or die(mysql_error());
    $myQuery='Select * from php_shop_products where product_id='.$productid;
    $results = mysql_query($myQuery);
    if($results===false){
        return die($myQuery."<br/><br/>".mysql_error());
    }
    else{
        return $results;
    }
    return die(mysql_error());
}

/*$results =ReadBooks(1);

while($row =mysql_fetch_array($results)){
    echo $row['name'];
}*/


?>



client.php

<?php

/**
 * @author 
 * @copyright 2013
 */

require 'lib/nusoap.php';

$client = new nusoap_client("http://localhost:8080/myfiles/examples/WS/service.php?wsdl");
$book_name="xyz";
$prices=$client->call('price',array("name"=>"$book_name"));

echo $prices . '<br/>';


$productid=1;
$results=$client->call('ReadBooks',array("productid"=>$productid));

while($row =mysql_fetch_array($results)){
    echo $row['name'];
}



?>


it's returning error:
VB
First function result : 200 //success

//second function error

Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampp\htdocs\myfiles\examples\WS\client.php on line 20




Could you tell me where I went wrong.

Thanks in advance...
Posted
Updated 23-Jul-13 19:12pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900