使用 PHP 使用 SOAP 更新数据库创建 Web 服务
Create Web Service with SOAP update to Database with PHP
我想通过 SOAP wsdl 创建用于更新数据库的 Web 服务
我试试这些代码:
require_once('dbconn.php');
require_once('lib/nusoap.php');
$server = new nusoap_server();
function editBookData($id,$title,$author_name,$price,$isbn,$category){
global $dbconn;
$sql = "UPDATE books SET title = :title, author_name = :author_name, price=:price, isbn=:isbn, category= :category WHERE id= :id";
// prepare sql and bind parameters
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(':id', $id);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':author_name', $author_name);
$stmt->bindParam(':price', $price);
$stmt->bindParam(':isbn', $isbn);
$stmt->bindParam(':category', $category);
// insert a row
$stmt->execute();
// $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$data="Update Success!";
return json_encode($data);
$dbconn = null;
}
$server->configureWSDL('booksServer', 'urn:book');
$server->register('editBookData',
array('id' => 'xsd:integer'), //parameter
array('data' => 'xsd:string'), //output
'urn:book', //namespace
'urn:book#editBookData' //soapaction
);
$server->service(file_get_contents("php://input"));
但似乎不起作用,我是 SOAP 的新手API这些问题有什么解决方案吗?
我找到了这些错误的解决方案 SQL 查询字符串错误。
$sql = "UPDATE books SET title = '$title', author_name = '$author_name', price='$price', isbn='$isbn', category= '$category' WHERE id= '$id'";
我想通过 SOAP wsdl 创建用于更新数据库的 Web 服务 我试试这些代码:
require_once('dbconn.php');
require_once('lib/nusoap.php');
$server = new nusoap_server();
function editBookData($id,$title,$author_name,$price,$isbn,$category){
global $dbconn;
$sql = "UPDATE books SET title = :title, author_name = :author_name, price=:price, isbn=:isbn, category= :category WHERE id= :id";
// prepare sql and bind parameters
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(':id', $id);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':author_name', $author_name);
$stmt->bindParam(':price', $price);
$stmt->bindParam(':isbn', $isbn);
$stmt->bindParam(':category', $category);
// insert a row
$stmt->execute();
// $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$data="Update Success!";
return json_encode($data);
$dbconn = null;
}
$server->configureWSDL('booksServer', 'urn:book');
$server->register('editBookData',
array('id' => 'xsd:integer'), //parameter
array('data' => 'xsd:string'), //output
'urn:book', //namespace
'urn:book#editBookData' //soapaction
);
$server->service(file_get_contents("php://input"));
但似乎不起作用,我是 SOAP 的新手API这些问题有什么解决方案吗?
我找到了这些错误的解决方案 SQL 查询字符串错误。
$sql = "UPDATE books SET title = '$title', author_name = '$author_name', price='$price', isbn='$isbn', category= '$category' WHERE id= '$id'";