我有返回數組的數組的一個問題,我使用的NuSOAP使得在PHP Web服務,這裏是我的代碼:陣列的NuSOAP PHP Web服務的回報陣列
server.php
<?php
//libreria de nusoap
require_once ('nusoap/lib/nusoap.php');
$miURL = 'http://localhost/webservice/';
$server = new soap_server();
$server->configureWSDL('Web Service de Pruebas', $miURL);
$server->wsdl->schemaTargetNamespace = $miURL;
$server->wsdl->addComplexType(
'array_php',
'complexType',
'struct',
'all',
'',
array(
'pk' => array('name' => 'pk', 'type' =>'xsd:int'),
'rol' => array('name' => 'rol', 'type' =>'xsd:string'),
'descripcion' => array('name' => 'descripcion', 'type' =>'xsd:string')
)
);
$server->wsdl->addComplexType(
'array_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:array_php[]'
)
),
'tns:array_php'
);
$server->register('prueba', // method name
array(), // input parameters
array('return' => 'tns:array_array'), // output parameters
$miURL, // namespace
$miURL . '#prueba', // soapaction
'rpc', // style
'encoded', // use
'Get Specific array_php' // documentation
);
function prueba()
{
$con = mysql_connect('localhost', 'root', '1234');
mysql_selectdb('laboral', $con);
$sql = "SELECT * FROM roles";
$q = mysql_query($sql);
$item = array();
while($r = mysql_fetch_assoc($q)){
$item[] = $r;
}
return $item;
}
if(!isset($HTTP_RAW_POST_DATA))
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
$server->service($HTTP_RAW_POST_DATA);
?>
client.php
<?php
//libreria nusoap
require_once ('nusoap/lib/nusoap.php');
//lineas de configuracion
$serverURL = 'http://localhost/webservice/ws2.php?wsdl';
$cliente = new nusoap_client($serverURL);
//sí error de conexión:
$error = $cliente->getError();
if($error){
echo "<p> '.$error.' </p>";
echo '<p style="color:red;'>htmlspecialchars($cliente->getDebug(), ENT_QUOTES).'</p>';
die();
}
echo "<br/>";
$arreglo2 = $cliente->call('prueba');
echo "<br/>";
for($i=0; $i<3; $i++){
print_r($arreglo2[$i]['pk']);
print_r($arreglo2[$i]['rol']);
print_r($arreglo2[$i]['descripcion']);
echo "<br/>";
}
?>
問題是回報,無非是回到我的客戶,我不知道會發生什麼,我已經讀了很多論壇,但我不能找到一個答案,請如果有一個人知道幫助我在這裏
TY和對不起我的英語
可能只是我,但我沒有看到你實際返回什麼東西。 – Peon
第一個錯誤是,您沒有在while循環中爲數組分配mySQL響應的索引。告訴我你的查詢響應如何,我可以給你一個工作的例子。 (只需要查詢表的列名) – OrcHound