0

我创建了这段代码来使用 nusoap 将数据插入到我的数据库中。一切正常,但数据没有插入我的数据库。

这是代码

require_once('nusoap/nusoap.php');

$server = new soap_server();

$server->configureWSDL('Insert Order', 'urn:InsertOrder');

$server->soap_defencoding = 'utf-8';

$server->register(
    'InsertOrder',
    array('FirstName' => 'xsd:Testing', 'LastName' => 'xsd:NuSoap'),
    array('return' =>'xsd:boolean'),
    'urn:InsertOrderwsdl', 
    'urn:InsertOrderwsdl#InsertOrder', 
    'rpc', 
    'literal'      
);

function InsertOrder($FirstName, $LastName) {

$connect = mysql_pconnect("localhost","root","");
if ($connect) {       
    if(mysql_select_db("database", $connect)) {
  mysql_query("INSERT INTO myuser SET FirstName='$FirstName',     LastName='$LastName'");   
        return true;
    }
}
return false;
}

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

这是wsdl文件:

<definitions targetNamespace="urn:InsertOrder">
<types>
<xsd:schema targetNamespace="urn:InsertOrder">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema></types>
<message name="InsertOrderRequest">
<part name="FirstName" type="xsd:Testing"/>
<part name="LastName" type="xsd:NuSoap"/>
</message>
<message name="InsertOrderResponse">
<part name="return" type="xsd:boolean"/>
</message><portType name="Insert OrderPortType">
<operation name="InsertOrder">
<input message="tns:InsertOrderRequest"/>
<output message="tns:InsertOrderResponse"/>
</operation>
</portType>
<binding name="Insert OrderBinding" type="tns:Insert OrderPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="InsertOrder">
<soap:operation soapAction="urn:InsertOrderwsdl#InsertOrder" style="rpc"/>
<input>
<soap:body use="literal" namespace="urn:InsertOrderwsdl"/>
</input>
<output>
<soap:body use="literal" namespace="urn:InsertOrderwsdl"/>
</output>
</operation></binding>
<service name="Insert Order">
<port name="Insert OrderPort" binding="tns:Insert OrderBinding">
<soap:address location="http://localhost/nuSoap/MyService.php"/>
</port>
</service>
</definitions>

在 wsdl 文件中,参数和输出都可以。我不明白为什么不将这些数据放入我的数据库中?我必须在这里错过一些东西。任何人都知道为什么会这样?先感谢您。

4

3 回答 3

0

您的 Insert 语句看起来更像是一个更新语句。你能改变吗

mysql_query("INSERT INTO myuser SET FirstName='$FirstName',     LastName='$LastName'");

mysql_query("INSERT INTO myuser(FirstName,LastName) values('$FirstName', '$LastName')");
于 2013-12-05T07:53:09.420 回答
0

我的脚本没有错误,它正在通过soap将数据插入我的mysql表中,我希望你在数据库连接中做错了什么。再检查一遍!或者我认为您的插入查询中有 sql 语法错误。下面是我的代码:

$sql="INSERT INTO employee (ename) VALUES('".$employee_name."')";
$res=mysql_query($sql);
if($res==true){
    return "Employee inserted";
}else{
    return "data not inserted";
}
于 2015-05-01T05:11:23.383 回答
0

而不是数组('FirstName' => 'xsd:Testing', 'LastName' => 'xsd:NuSoap'),

试试这个数组('FirstName' => 'xsd:string', 'LastName' => 'xsd:string'),

于 2019-01-17T08:18:45.853 回答