tags:

views:

41

answers:

1

I'm using PHP5 and NuSOAP - SOAP Toolkit for PHP. I created the server using the code below:

<?php
function getStockQuote($symbol) {
mysql_connect('localhost','user','pass');
mysql_select_db('test');
$query = "SELECT stock_price FROM stockprices WHERE stock_symbol = '$symbol'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
echo $row['stock_price'];
}

$a=require('lib/nusoap.php');
$server = new soap_server();

$server->configureWSDL('stockserver', 'urn:stockquote');

$server->register("getStockQuote",
            array('symbol' => 'xsd:string'),
            array('return' => 'xsd:decimal'),
            'urn:stockquote',
            'urn:stockquote#getStockQuote');
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
                  ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

The client has the following code:

<?php
require_once('lib/nusoap.php');
$c = new soapclientNusoap('http://localhost/stockserver.php?wsdl');
$stockprice = $c->call('getStockQuote',
          array('symbol' => 'ABC'));
echo "The stock price for 'ABC' is $stockprice.";

?>

The database was created using the code below:

CREATE TABLE `stockprices` (
`stock_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`stock_symbol` CHAR( 3 ) NOT NULL ,
`stock_price` DECIMAL(8,2) NOT NULL ,
PRIMARY KEY ( `stock_id` )
);
INSERT INTO `stockprices` VALUES (1, 'ABC', '75.00');
INSERT INTO `stockprices` VALUES (2, 'DEF', '45.00');
INSERT INTO `stockprices` VALUES (3, 'GHI', '12.00');
INSERT INTO `stockprices` VALUES (4, 'JKL', '34.00');

When I run the client the result I get is this:

The stock price for 'ABC' is . 75.00 is not being printed as the price.

A: 

the return method is missing in the function, maybe that is the problem.

return $row['stock_price'];
petingo0