繁体   English   中英

PHP Webservice 使用 nuSoap 和 mySQL

[英]PHP Webservice using nuSoap and mySQL

我目前正在开发一个 PHP 网络服务,它将被文档管理软件DocuWare 使用 现在它主要包括读取数据库并通过他们的 ID 获取值。 Web 服务的文件夹包含以下文件夹:

数据层

服务层

前端层

库(nusoap)

样品(nusoap)

dataLayer我有client.php

<?php
    require "../lib/nusoap.php";
        $url="http://localhost/service/dataLayer/service.php";
        $client=new nusoap_client($url."?wsdl",'wsdl');
        $code=$_POST[idCourse];
        $courses=$client->call('listCourses',array("code"=>$code),'uri:'.$url,'uri:'.$url.'/listCourses');
        if($client->fault){
        echo "Error";
        print_r($courses);
        }else{
            if($client->getError()){
                echo '<b>Error: '.$client->getError().'</b>';
            }else{
                print_r($courses);
            }
        }
?>

connection.php

<?php
    require(../dataLayer/auth.php);
    function connect(){
        $conn = mysql_connect($host,$hostuser,$hostpw)or die(mysql_error());
        mysql_select_db("tickets",$conn);
        return($conn);
    }
?>

考虑到这一点; 我制作了由一个简单的"service.php"文件组成的 serviceLayer。

<?php
    include('../lib/nusoap.php');
    require ('../dataLayer/connection.php');
    $url = "http://localhost/service/dataLayer/service.php";
    $server->configureWSDL("consult",$url);
    $server->wsdl->schematargetNamespace=$url;
    $server->soap_defencoding='utf-8';
    $server->register;
             ("listcourses",
             array("code"=> "xsd:string"),
             array("return => "xsd:string"), $url
             );

    function listcourses($code){
        $conn=connect();
        if($code!=0){
            $sql="select id from ticket where id='$code'";
        }else{
            $sql="select id from ticket";
        }
        $rs=mysql_query($sql,$conn);
        $i=0;
        $chainset="<?xml version='1.0' encoding='utf-8'?>";
        if($rs!=null){
            $chainset.="<courses>";
            if(mysql_num_rows($rs)>0){
                while ($row = mysql_fetch_row($rs)){
                    $chainset.="<course>";
                    $chainset.="<br>";
                    $chainset.="<code>".row[0]."<code>";
                    $chainset.="<br>";
                    $chainset.="<name>".row[1]."<name>";
                    $chainset.="</course";
                    $i++;
                }
            }else{
                $chainset.="<error>No data available</error>"
            }
            $chainset.="</course";
        }else{
            $chainset.="<error>Error".mysql_error()."</error>";
        }
        $repl=new soapval('return','xsd:string',$chainset);
        return $repl;
    }
    if(!isset($HTTP_RAW_POST_DATA))
    $HTTP_RAW_POST_DATA=file_get_contents('php://input');
    $server->service($HTTP_RAW_POST_DATA);
?>

理论上一切正常 我做了前端层,这只是一个简单的形式。

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script src="jquery/jquery2.1.js"></script>
        <script>
            function sendForm(form){
                document.getElementById(form).submit();
            }
        </script>
    </head>
    <body>
        <div class="container">
            <section id="content">
                <form id="login" name="login" method="POST" action="../dataLayer/client.php">
                    <div>
                        <label for="idCourse">Course</label>
                    </div>
                    <br>
                    <div>
                        <input type="text" maxlength="2" id="idCourse" name="idCourse" placeholder="Example - 76" required="required" size="10"/>
                    </div>
                    <input type="reset" name="button" value="Reset"/>
                    <input type="submit" name="button" value="Submit"/>
                </form>
            </section>
        </div>
    </body>
</html>

我收到以下错误:

(: ) 注意:在第 5 行调用堆栈上的 C.\wamp64\www\service\dataLayer\client.php 中使用未定义的常量 idCourse-假定为 'idCourse'

Time Memory Function Location 1 0.0003 245144 {main}( )...\client.php:0 Error: wsdl error: XML error parsing WSDL from

http://localhost/service/dataLayer/service.php?wsdl在第 2 行:

无效的文档结尾

我不知道出了什么问题,因为一切似乎都很好。

正如Jaquarh所指出的,进行了以下更正:

在 client.php 中:

$code=$_POST['idCourse']; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM