2015-05-16 30 views
1

我想在我的web服务上返回一个mysql_query,但同样的 获取数据,但返回一个空数组。nuSoap web服务服务器不返回mysql查询

我想要得到这样一个数据:

array(
0=>array('id'=>int,'nome'=>string,'voltagem'=>int, 'potencia'=>doube, 'standby'=>doube) 
); 
<?php 
include("/lib/nusoap.php"); 


$servidor = new soap_server(); 

$servidor->configureWSDL("urn:Servidor"); 
$servidor->wsdl->schemaTargetNamespace = "urn:Servidor"; 


$servidor->wsdl->addComplexType(
    'produto', 
    'complexType', 
    'struct', 
    'all', 
    '', 
array(
    'id'  => array('name'=>'id',  'type'=>'xsd:int'), 
    'nome'  => array('name'=>'nome', 'type'=>'xsd:string'), 
    'voltagem' => array('name'=>'voltagem','type'=>'xsd:int'), 
    'potencia' => array('name'=>'potencia','type'=>'xsd:int'), 
    'standby' => array('name'=>'standby', 'type'=>'xsd:int') 
) 
); 

$servidor->register('buscar', 
    array('produtonome'=>'xsd:string'), 
    array('retorno'=>'tns:produto'), 
    'urn:Servidor.buscar', 
    'urn:Servidor.buscar', 
    'rpc', 
    'econded', 
    'apenas um exemplo usando o nuSuop PHP' 
); 

function buscar($produtonome){ 
    $db = new mysqli('localhost', 'root', '', 'produto'); 

    if($db->connect_errno > 0){ 
     die('Unable to connect to database [' . $db->connect_error . ']'); 
    } 


$sql = <<<SQL SELECT * FROM `produto` LIMIT 1 SQL; 

    if(!$result = $db->query($sql)){ 
     die('There was an error running the query [' . $db->error . ']'); 
    } 
    while($row = $result->fetch_assoc()){ 

     $dados['id']  = $row['id']; 
     $dados['nome']  = $row['nome']; 
     $dados['voltagem'] = $row['voltagem']; 
     $dados['potencia'] = $row['potencia']; 
     $dados['standby'] = $row['standby'];  
    } 
} 


$HTTP_RAW_POST_DATA = (isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : 'teste'); 

$servidor->service($HTTP_RAW_POST_DATA); 
?> 
+0

您是否对它进行排序?我也在寻找同样的东西,但似乎没有得到它的工作。 –

+0

经过数小时的努力,我决定用json返回搜索结果。其他人没有成功就有同样的错误。肥皂上的一些错误 –

回答

0

小时后尝试我决定使用JSON返回SEACH。其他人没有成功就有同样的错误。肥皂上的一些错误