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
require 'lib/nusoap.php';
require 'functions.php';
$server = new nusoap_server();
$server -> configureWSDL('WS'.'urn:WS');
$server -> register(
"price",
array("name" => 'xsd:string'),
array("return" => 'xsd:inter')
);
$server -> register(
"ReadBooks",
array("productid" => 'xsd:inter'),
array("return" => 'xsd:unbounded')
);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
functions.php
<?php
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());
}
?>
client.php
<?php
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:
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...