简体   繁体   English

带有nusoap的PHP,MYSQL Web服务

[英]PHP, MYSQL Web Service with nusoap

I'm starting to learn about web services and I'm doing some tests. 我开始学习Web服务,并且正在做一些测试。

I'm trying to write a service to pass all the data of a table into my client but i can't make it work. 我正在尝试编写一项服务,以将表的所有数据传递到客户端,但是我无法使其正常工作。

The first one 'servei' works, but the second doesn't. 第一个'servei'有效,但第二个无效。

Any suggestions will be appreciated. 任何建议将不胜感激。 Thanks 谢谢

service.php 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 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 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);    

    ?>

OK, I handled it. 好的,我处理了。

If you are using PHP 5.4 you have to comment line 6132 in nusoap.php. 如果您使用的是PHP 5.4,则必须在nusoap.php中注释6132行。

Couldn't this be fixed if we were to change it from: 如果我们将其更改为以下内容,则无法解决此问题:

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

To: 至:

$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