使用nusoap错误在Php中创建Web服务 [英] Creating Web Service in Php using nusoap Error

查看:74
本文介绍了使用nusoap错误在Php中创建Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在学习php。



我在php中创建了Web服务使用nusoap.dll。我写了价格测试方法它返回整数它工作正常,但是当我获取数据库时,返回数组它返回错误。我试图解决这个错误,但它仍然给出了错误。



你能告诉我哪里出错了。



我的PHP代码是:



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:

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...

推荐答案

server = new nusoap_server();
server = new nusoap_server();


server - > configureWSDL('WS'。'urn:WS');
server -> configureWSDL('WS'.'urn:WS');


server - >注册(
price,//函数名称
array(name=>'xsd:string'),//输入
array(return=> 'xsd:inter')//输出
);
server -> register( "price", //name of the function array("name" => 'xsd:string'), //inputs array("return" => 'xsd:inter') //outputs );


这篇关于使用nusoap错误在Php中创建Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆