[Phpwm] nuSoap question
Ray Masa
raymasa at hotmail.com
Thu Oct 5 09:35:33 BST 2006
Hi all,
Not sure if this is a relevant question for this forum, since I think the
issue is more to do with nuSoap rather than PHP or mySQL, but I figured I
ask any way. I am getting by feet wet on web services and found nuSoap,
which seems like a very cool tool. I followed an example at codewalkers.com
(http://codewalkers.com/tutorials/74/1.html) which worked very well. I then
proceed to modify that example a bit further to retrieve data from the
database dynamically (you enter information in the form on the soap client
and get the result back based on the parameter you entered). I was able to
retrieve a single record from the database, but not multiple records. When I
tried the php code (without soap) to retrieve data from the database, I was
able to retrieve multiple records, so it seems like the SQL statement is
correct. If so, why is it not working with nuSoap? Any suggestions on what I
am doing wrong?
The soap server is as follows:
Code:
<?php
function getStockQuote($id) {
mysql_connect('host','username','password');
mysql_select_db('db');
$query = "SELECT * FROM table "
. "WHERE id = '$id' ";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)){
return $row['stock'];
}
}
require('lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('server', 'urn:stockquote');
$server->register("getStockQuote",
array('symbol' => 'xsd:string'),
array('return' => 'xsd:string'),
'urn:stockquote',
'urn:stockquote#getStockQuote');
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
What I am trying to do is retrieve all stocks associated with the id that is
entered in the form on the soap client. But it is only returning the first
record in the table.
If I try just the following SQL statement in a php file, it return all
records:
Code:
mysql_connect('host','username','password');
mysql_select_db('db');
$query = "SELECT * FROM table "
. "WHERE id = '$id' ";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)){
echo $row['stock'];
}
The soap client for the above server is:
Code:
<html>
<body>
<form method="get" action="client.php">
ID: <input name="symbol" type="text" value="">
<br>
<br>
<input type="submit">
</form>
<?php
$symbol = $_GET['symbol'];
if ($symbol) {
require_once('lib/nusoap.php');
//we create an array with the element name that has the form value of name
//now we must create a soapclient object
$c = new soapclient('http://domain.com/server.php');
//now we call the server.
$stockprice = $c->call('getStockQuote',
array('symbol' => $symbol));
echo "Information for $symbol is $stockprice.";
}
?>
</body>
</html>
So, it seems that I am doing something incorrectly in the soap server.
Thanks for your help.
Ray
More information about the Phpwm
mailing list