繁体   English   中英

php nusoap未通过内容

[英]Php nusoap not passing content

我在这个角落以及编程方面都是新手。 我正在尝试基于nusoap和php创建一个Web服务,以便它从mysql数据库中传递一些值。 我环顾了许多网站(包括堆栈溢出的答案),发现了一些我尝试过但未成功的解决方案。 由于某些原因,当我执行客户端访问服务时,它总是空的。 看了一天之后,我现在只看到信件了。

如果有人可以提供解决方案的方法,我将不胜感激。 谢谢!

服务器端

<?php
    include 'nusoap.php';

    $server=new nusoap_server();
    $server->configureWSDL("demo"."urn:demo");


    $server->register(
            'gamedata', 
            array(),    
            array("estadio"=>'xsd:string',
                  "nome"=>'xsd:string',
                )
            );

    function gamedata(){
        $con=mysql_connect('127.0.0.1:3306', 'root', '') or die ("Erro ao conectar...");
        mysql_select_db("testar",$con) or die ("Erro ao seleccionar DB...");

        $queryforestadio="SELECT nome,cidade FROM estadio";
        //$queryforjogos = "SELECT data, id_selecao1, id_selecao2 FROM jogo";

        while($resultestadio = mysql_fetch_array($queryforestadio)){
      $estadios[] = array('nome'=>$resultestadio['nome'],
                          'cidade'=>$resultestadio['cidade'],
                          ); 
          echo "Message from function: ".$estadios['nome']['cidade'];
    }
    return $estadios;

    }
    if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
    $server->service($HTTP_RAW_POST_DATA);

?>

客户端

<?php    

        require('nusoap.php');
        $client = new nusoap_client('http://localhost:8048/webservice/index.php');
        $response= $client->call('gamedata');



    $r = $response;
    $count = count($r);

    for($i=0; $i<=$count-1;$i++){
        echo "This is name: ".$r[$i]['nome'];
        echo "This is city: ".$r[$i]['cidade'];
    }

该代码是毫无意义的/冗余的:

  $estadios[] = array('nome'=>$resultestadio['nome'],
                      'cidade'=>$resultestadio['cidade'],
                      ); 

您只在查询中获取nomecidade字段,因此$resultstadio已经是这两个字段及其值的数组。

然后这与您在上面构建的结构不匹配:

      echo "Message from function: ".$estadios['nome']['cidade'];

您可能应该更像这样:

while($resultestadio = mysql_fetch_array($queryforestadio)){
    $estadios[] = $resultestadio;
    echo "Message from function: ".$resultestadio['nome'] ',' . $resultestadio['cidade'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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