php nusoap返回数组

问题描述 投票:1回答:1

我是网络服务的新手。

我想在php nusoap服务器端编写一个泛型函数,它可以查询(从多个表中获取数据)并根据mysql返回的结果返回一个动态数组...

这是服务器代码......

require_once ('../lib/nusoap.php');
$server = new soap_server;
$server->register('getallbook');
function getallbook()
{
$conn = mysql_connect('localhost','root','');
mysql_select_db('apexinventry', $conn);

$sql = "SELECT * FROM users";
$q  = mysql_query($sql);
while($r = mysql_fetch_array($q)){
  $items[] = array('cd'=>$r['id'],'title'=>$r['userid'],'author'=>$r['password'],'publisher'=>$r['groupid']); 
}
return $items;

}

$server->service($HTTP_RAW_POST_DATA);

这是客户代码......

require_once ('../lib/nusoap.php');

$client = new soapclient('http://127.0.0.1/test/server/index.php');

$response = $client->call('getallbook');

if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode.")</p>";
echo "String: ".$client->faultstring;
}
else
{
$r = $response;
$count = count($r);
?>
<table border="1">
<tr>
    <th>Code</th>
    <th>Title</th>        
    <th>Author</th>        
    <th>Publisher</th>        
</tr>
<?php
for($i=0;$i<=$count-1;$i++){
?>
<tr>
    <td><?php echo $r[$i]['cd'];?></td>
    <td><?php echo $r[$i]['title'];?></td>
    <td><?php echo $r[$i]['author'];?></td>                
    <td><?php echo $r[$i]['publisher'];?></td>        
</tr>
<?php
}
?>
</table>
<?php
}

我应该做些什么更改才能返回记录(数组)?

php arrays return nusoap
1个回答
0
投票

如何在SOAP声明中定义返回值?例如,这是我在wsdl中的内容:

$server->wsdl->addComplexType('ResultObject',
 'complexType',
 'struct',
 'all',
 '',
      array(
       'result' => array('name' => 'result',
           'type' => 'xsd:string'),
       'addl_info' => array('name' => 'addl_info',
           'type' => 'xsd:string')
      )
);

这是我在同一个wsdl中的函数注册:

$server->register('addGroupRequest',                // method name
array('auth_name' => 'xsd:string',
    'password' => 'xsd:string',
    'group_objid' => 'xsd:int',         // input parameters
    'source_character_objid' => 'xsd:int',          // input parameters
    'message' => 'xsd:string'),         // input parameters
array('ResultObject' => 'tns:ResultObject'),      // output parameters
'urn:Groupwsdl',                      // namespace
'urn:Groupwsdl#addGroupRequest',                // soapaction
'rpc',                                // style
'encoded',                            // use
'add group request for the character '            // documentation
);

为了获得数组,我只需要调用$return['addl_info']$return['result']

© www.soinside.com 2019 - 2024. All rights reserved.