phpsoapnusoap

Create Web Service with SOAP update to Database with PHP


I want to create web service for update database by SOAP wsdl I try these code:

 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"));

but seem to be not working, i am new for SOAP API any solution for these problem?


Solution

  • I found solution for these error wrong SQL query string.

     $sql = "UPDATE books SET title = '$title', author_name = '$author_name', price='$price', isbn='$isbn', category= '$category' WHERE  id= '$id'";