Welcome Guest, Not a member yet? Register   Sign In
DB result to XMLRPC response
#1

[eluser]jeffpeck[/eluser]
Has anyone found a nice way to go from a DB result object (or array) an output an XMLRPC response (with the types like string or int included in an array for each element?
#2

[eluser]jeffpeck[/eluser]
OK, I have written a function accomplishes this:

Code:
function encode_for_xmlrpc(&$element) {
    if (is_array($element)) {
        foreach ($element as $key=>$item)
             encode_for_xmlrpc($element[$key]);
            
             $element = array($element, 'struct');
        }
         else {
             if (is_numeric($element)) {
                  if (intval($element) == $element)
                      $type = 'int';
                  elseif (floatval($element) == $element)
                      $type = 'double';
                }
             elseif (is_string($element)) {
                      $type = 'string';
                }
                
             $element = array($element, $type);
        }
}
        
encode_for_xmlrpc($result);

Basically, if you have a DB result as an array and you want to send it to an XML-RPC client as an object, it has to have types added to it. This function should do the trick




Theme © iAndrew 2016 - Forum software by © MyBB