简体   繁体   中英

nuSoap webservice server dont return mysql query

i'm trying return a mysql_query on my webservice but the same get the data but return a null array.

i'm trying get a data like:

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);
?>

After hours trying i decides return the seach with json. Others people had the same error without sucess. Some bug on soap

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM