gpt4 book ai didi

Php nusoap 不传递内容

转载 作者:行者123 更新时间:2023-11-29 23:09:04 24 4
gpt4 key购买 nike

我是这方面的新手,也是编程新手。我正在尝试创建一个基于 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 已经是仅包含这两个字段的数组以及他们的值(value)观。

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

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

你可能应该有更多类似这样的东西:

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

关于Php nusoap 不传递内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28158186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com