Joined: 23 Sep 2010 |
Posts: 1 |
|
|
|
Posted: Thu Sep 23, 2010 8:45 am |
|
|
|
|
|
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.
<?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!
|