NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
multiple row return - newbie question


Joined: 23 Sep 2010
Posts: 1
Reply with quote
Hi,

A typical scenario - a newbie asking a newbie question.

I am trying to create a method that will return a MySQL table, so columns and multiple rows. My current code is able to retrieve a single row of the database, but nothing more.

Code:
<?php



// Define an array complex type
$server->wsdl->addComplexType(
  'RegisteredUsersArray',
  'complexType',
  'struct',
  'all',
  '',
  array(
   'id_client' => array('name' => 'id_client', 'type' => 'xsd:string'),
   'client_type' => array('name' => 'client_type', 'type' => 'xsd:string'),
   'login' => array('name' => 'login', 'type' => 'xsd:string'),
   'ip_address' => array('name' => 'ip_address', 'type' => 'xsd:string'),
   'registration_time' => array('name' => 'registration_time', 'type' => 'xsd:string'),
   'id_farscape' => array('name' => 'id_farscape', 'type' => 'xsd:string')
   )
);

// Register the method to expose
$server->register(
   // method name
   'viewRegisteredCustomers',
   // input parameters   
    array('registered_login' => 'xsd:string'), 
   // output parameters
    array('return' => 'tns:RegisteredUsersArray'), 
    'http://helper.com',
   // namespace   
   // soapaction
    'urn:helper#viewRegisteredCustomers',
   // style
    'rpc',
   // use
    'encoded',
   // documentation
    'Says hello to the callerfunction shows the current registered clients using the registered_users table. It can filter the result by login, ip.'
);
// Define PHP function
function viewRegisteredCustomers($registered_login) {

   if (is_string($registered_login)) {
   
         //connect to mysql
           $link   = @mysql_connect('localhost', 'root', '');
         mysql_db_query('farscape',"INSERT INTO `log` (timestamp) VALUES('1')");
         $query = "SELECT id_client, client_type, login, ip_address, registration_time, id_farscape FROM registered_users WHERE login like '" . mysql_escape_string((string)$registered_login) . "%'";
         $result = mysql_query($query);
           // error handling, !disabled for now!
            if (!$result) {
                return new soap_fault('Server', '','Internal MySQL server error.');
            }
         if (!mysql_num_rows($result)) {
                return new soap_fault('Server', '','There are no registered clients.');
            }
            dbclose; // mysql_close($link);
            while($row = mysql_fetch_array($result, MYSQL_ASSOC))
         {
         return $row;
         }
         

         
   }
      // we accept only a string
        else {
          return new soap_fault('Client', '', 'Service requires a string parameter.');
        }
}
         
         
         
         
   return $result;


?>


I do think that I need to create a multidimensional array, but how to attempt it with nusoap?

Thanks!
View user's profileFind all posts by irontomSend private message
multiple row return - newbie question
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic