2015-01-26 3 views
0

저는 프로그래밍뿐만 아니라이 코너에서도 새로운 편입니다. nusoap과 PHP를 기반으로 웹 서비스를 만들려고하고 있으므로 mysql 데이터베이스에서 값을 몇 개 전달합니다. 많은 웹 사이트 (스택 오버플로 응답 포함)를 둘러 보았습니다.하지만 시도했지만 성공하지 못한 몇 가지 솔루션을 발견했습니다. 어떤 이유로 클라이언트에 서비스를 액세스 할 때 항상 비어있게됩니다. 하루 만에이 글을 보았는데 지금은 편지 만 볼 수 있습니다 ...PHP는 내용을 전달하지 않습니다.

누군가가 솔루션을 제공 할 수 있다면 많은 도움이 될 것입니다. 고맙습니다!

서버 측

<?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']; 
    } 

답변

0

이 코드는/무의미한 중복 :

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

당신 만 nome를 가져 오는 것 nd cidade 필드를 쿼리에 포함 시키십시오. 따라서 $resultstadio은 이미이 두 필드와 값의 배열입니다.

그리고 이것은 당신이 위에 건설하고있는 구조와 일치하지 않습니다

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

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

당신은 아마 이런 식으로 뭔가를해야한다을

관련 문제