<?php
/*
* Simple SOAP SQL Demo
* Created: Apr 18, 2007
* License: LGPL (open source)
* BungeeLabs, Inc.
*
* This PHP script demonstrates the simplicity of creating rich web services
* from simple SQL statements using SOAP SQL.
*
* Dependencies:
* NuSOAP at http://dietrich.ganx4.com/nusoap
* PEAR MDB2 at http://pear.php.net/package/MDB2
*/
require_once("soapsql.php");
$soapsql = new soapsql();
$soapsql->setDebug(true);
$soapsql->register(
'SQL', //Web service name
'http://testsoapsql/', //Name space
'mysqli', //Database type
'root', //DB username
'password', //DB password
'localhost',//DB host
'test'); //Database name
if ($soapsql->isError())
die ($soapsql->getError());
/**
* Demonstrate an SQL web service function that queries the database.
*/
// We take as input a name and return an array of name, age pairs (the table row).
// NOTE: see "http://www.w3.org/TR/xmlschema-2/#dt-built-in" for all XSD datatypes for in/out parameters.
$inParams = array('name' => 'xsd:string');
$outParams = array('name' => 'xsd:string', 'age' => 'xsd:int');
// Notice the $name value does NOT need '' around it, it will be *automatically* quoted and escaped.
$sqlQuery = 'select name, age from mytable where name = $name';
// Create a select-based web service function using createWSDLFunction().
// Three support WSDL structures will also be automatically created, called QueryRequestType, QueryResponseType, and QueryResultType,
// which contain the $inParams, an array of $outParams, and the $outParams stucture, respectively.
$soapsql->addQueryWSDLOperation('Query', $inParams, $outParams, $sqlQuery);
if ($soapsql->isError())
die ($soapsql->getError());
/**
* Demonstrate an SQL web service function that modifies the database
*/
// Create an insert-based web service function using createWSDLFunction().
// It takes a name string and an age integer as inputs.
$inParams = array('name' => 'xsd:string', 'age' => 'xsd:int');
// Notice the $name and $age values do NOT need '' around it, it will be *automatically* quoted and escaped according to type.
$sqlModify = 'insert into mytable (name, age) values ($name, $age)';
$soapsql->addModifyWSDLOperation('Insert', $inParams, $sqlModify);
if ($soapsql->isError())
die ($soapsql->getError());
//Do the actual servicing of the request
$soapsql->serviceWSDL();
if ($soapsql->isDebug()) {
file_put_contents("test_soapsql.log", $soapsql->getDebug()."\r\n".$soapsql->getSOAPDebug());
}
?>