簡體   English   中英

帶有nusoap的PHP,MYSQL Web服務

[英]PHP, MYSQL Web Service with nusoap

我開始學習Web服務,並且正在做一些測試。

我正在嘗試編寫一項服務,以將表的所有數據傳遞到客戶端,但是我無法使其正常工作。

第一個'servei'有效,但第二個無效。

任何建議將不勝感激。 謝謝

service.php

require 'lib/nusoap.php';    

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

include 'functions.php';    

$server->wsdl->addComplexType('servei', 'complexType', 'struct', 'all', '', array(
    'preu_antic' => array('name' => 'preu_antic', 'type' => 'xsd:float'),
    'preu_actual' => array('name' => 'preu_actual', 'type' => 'xsd:float'),
    'descompte_servei' => array('name' => 'descompte_servei', 'type' => 'xsd:float'),
));    

$server->wsdl->addComplexType('ServiceTypes', 'complexType', 'struct', 'all', '', array(
    'id_tipus_servei' => array('name' => 'id_tipus_servei', 'type' => 'xsd:inter'),
    'nom_tipus_servei' => array('name' => 'nom_tipus_servei', 'type' => 'xsd:string'),
    'descripcio_tipus_servei' => array('name' => 'descripcio_tipus_servei', 'type' => 'xsd:string'),
));    

$server->wsdl->addComplexType('ArrayOfServiceTypes', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
    array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:ServiceTypes[]')), 'tns:ServiceTypes');    

$server->register('servei', array("id_servei" => 'xsd:inter'), array("return" => 'tns:servei'));
$server->register('getServiceTypes', array("idioma" => 'xsd:string'), array("return" => 'tns:ArrayOfServiceTypes'));    


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

functions.php

function servei($id){
    conexio();
    $query_servei = mysql_query("SELECT * FROM servei WHERE id_servei = '$id'")or die(mysql_error());
    $row = mysql_fetch_array($query_servei);
    $preu_antic = $row['preu_antic'];
    $preu_actual = $row['preu_actual'];
    $descompte_servei = $row['descompte_servei'];

    $servei = array('preu_antic'=>$preu_antic,'preu_actual'=>$preu_actual,'descompte_servei'=>$descompte_servei);

    return $servei;
}    

function getServiceTypes($idioma){
    conexio();
    $query = mysql_query("SELECT id_tipus_servei, nom_tipus_servei, descripcio_tipus_servei FROM idioma_tipus_servei WHERE id_idioma = '$idioma'") or die(mysql_error());
    $n = 0;
    while ($row = mysql_fetch_array($query)) {
        $result[$n]['id_tipus_servei'] = $row['id_tipus_servei'];
        $result[$n]['nom_tipus_servei'] = $row['nom_tipus_servei'];
        $result[$n]['descripcio_tipus_servei'] = $row['descripcio_tipus_servei'];
        $n++;
    }
    return $result;
} 
?>

client.php

<?php
    require 'lib/nusoap.php';
    include 'functions.php';
    $client = new nusoap_client("http://192.168.8.155:8090/webservice/service.php?wsdl");    

   //$id=1;
   // $servei = $client -> call('servei',array("id_servei"=>"$id"));
   // print_r($servei);    


    $idioma ='ca';
    $servicetypes = $client -> call('getServiceTypes',array("idioma"=>"$idioma"));
    print_r($servicetypes);    

    ?>

好的,我處理了。

如果您使用的是PHP 5.4,則必須在nusoap.php中注釋6132行。

如果我們將其更改為以下內容,則無法解決此問題:

$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");

至:

$this->debug("serializing array element: $k, $v of type: " . $typeDef['arrayType'] )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM