[Phpwm] nuSoap question

Jon Spriggs jon at spriggs.org.uk
Thu Oct 5 09:42:53 BST 2006


To be honest Ray, I've never had it returning array values properly -
I've even got to the point where I build a string array first (using
symbols outside the expected range) and then split it at the far end.

It is possible to return an array, but I think you need to create a
new "array" type, which specifies the number of entries in the array
(so for $Key=>$Value, that'd be 2 I think, unless
$Var['fred']="twist"; $var['george']="stick"; is 2... I'm not sure.)
But even then, I'm not sure. If you figure it out, can you let me know
how you did it :)

Regards,

Jon

On 05/10/06, Ray Masa <raymasa at hotmail.com> wrote:
> 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
>
>
>
> _______________________________________________
> Phpwm mailing list
> Phpwm at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/phpwm
>



More information about the Phpwm mailing list