0

我想将服务器的数据以多行的形式显示到客户端。当前的实现只向客户端显示一行,即“ABC”的值这是服务器端:

<?php
    function getStockQuote($symbol) {

        mysql_connect('server','user','pass');
        mysql_select_db('test');
        $query = "SELECT stock_price FROM stockprices "
               . "WHERE stock_symbol = '$symbol'";
        $result = mysql_query($query);

        $row = mysql_fetch_assoc($result);
        return $row['stock_price'];
    }

    require('nusoap.php');

    $server = new soap_server();

    $server->configureWSDL('stockserver', 'urn:stockquote');

    $server->register("getStockQuote",
                    array('symbol' => 'xsd:string'),
                    array('return' => 'xsd:decimal'),
                    'urn:stockquote',
                    'urn:stockquote#getStockQuote');

    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
                          ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA);
?>

这是客户端:

<?php
    require_once('nusoap.php');

    $c = new soapclient('http://localhost/stockserver.php');

    $stockprice = $c->call('getStockQuote',
              array('symbol' => 'ABC'));

    echo "The stock price for 'ABC' is $stockprice.";

?>
4

1 回答 1

1

您必须将 WSDL 指定为端点,因此使用 wsdl 更改端点,并且需要调用您的方法(call方法在您的服务器上不存在)

我测试和工作的客户端代码:

<?php
require_once('nusoap.php');

$c = new soapclient('http://localhost/stockserver.php?wsdl');

$stockprice = $c->getStockQuote('ABC');
echo "The stock price for 'ABC' is $stockprice.";

?>

停止使用已弃用的 mysql_* 函数

于 2013-10-03T10:18:17.593 回答