[英]PHP Webservice using nuSoap and mySQL
I'm currently developing a PHP webservice that will be consumed by the Document Management Software DocuWare .我目前正在开发一个 PHP 网络服务,它将被文档管理软件DocuWare 使用。 Right now it mostly consists of reading the database and getting a value by their ID.
现在它主要包括读取数据库并通过他们的 ID 获取值。 The folder for the webservice consists of the following folders:
Web 服务的文件夹包含以下文件夹:
dataLayer
数据层
ServiceLayer
服务层
frontEndLayer
前端层
lib (nusoap)
库(nusoap)
samples (nusoap)
样品(nusoap)
In dataLayer
I have client.php
在
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);
}
}
?>
and connection.php
和
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);
}
?>
With that in mind;考虑到这一点; I made the serviceLayer which consists of a simple
"service.php"
file.我制作了由一个简单的
"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);
?>
Theorically everything is OK .理论上一切正常。 I made the front end layer, which is just a simple form.
我做了前端层,这只是一个简单的形式。
<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>
And I get the following error:我收到以下错误:
(: ) Notice: Use of undefined constant idCourse- assumed 'idCourse' in C.\wamp64\www\service\dataLayer\client.php on line 5 Call Stack
(: ) 注意:在第 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
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 on line 2:
http://localhost/service/dataLayer/service.php?wsdl在第 2 行:
Invalid document end
无效的文档结尾
I don't know what's wrong since everything seems to be fine.我不知道出了什么问题,因为一切似乎都很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.