• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML-RPC ... sending a query result back as a result

#1
[eluser]skattabrain[/eluser]
I'm probably missing something basic here, but I'm trying to send a query result back as a response from my xml-rpc server.

1 row is not a problem ... but if I wanted to send back ... say a list of my customers orders ... I'm having trouble.

Maybe the problem is I don't understand struct ... but here is my code, the client will then take the response and loop through it to generate an order list.

The server is using ODBC instead of the typical MySQL query ... but I doub tthis is the issue I'm having. Any thoughts? I'm majorly frustrated with this ...

Code:
function customerlist($request)
    {
        $query = $this->db->query("SELECT * FROM orders WHERE customer_id = 6");
        
        foreach($query->result() as $row)
        {
            $results[$row->order_id] = array(
                'order_id' => $row->order_id,
                'total_amount' => $row->total_amount
                    ), 'struct';
        }
        
        $response = array($results, 'struct');
        
        return $this->xmlrpc->send_response($response);
        
    }

#2
[eluser]Nick Husher[/eluser]
What is your server response when you visit http://yourhost.com/yourcontroller/customerlist ?

Also, as a stylistic suggestion, I'd define the $results object before you start using it.
Code:
$results = array();

#3
[eluser]skattabrain[/eluser]
here's the response fucntion ...


Code:
function customerlist($request)
    {
        $query = $this->db->query("SELECT * FROM AR_Customer");
        
        $results = array();
        
        foreach($query->result() as $row)
        {
            $results[$row->CustomerNo] = array(
                'CustomerNo' => $row->CustomerNo,
                'CustomerName' => $row->CustomerName, 'array'
                    );
        }
        
        $response = array($results, 'array');
        
        // Give the request back
        return $this->xmlrpc->send_response($response);
        
    }

here's what the XML the client outputs (with debugging on)

this error spirals into a pile of php errors with libraries/Xmlrpc.php

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined offset: 0</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1345</p>


Code:
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
<value>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>

The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.

#4
[eluser]skattabrain[/eluser]
I'm just not building my array correctly ... this has to be a simple

#5
[eluser]Michael Wales[/eluser]
Maybe I'm just not understanding the issue here... Sad

Code:
function customerlist($request) {
  $query = $this->db->get('AR_Customer');
  return $this->xmlrpc->send_response($query->result_array());
}

#6
[eluser]skattabrain[/eluser]
I see I've managed to rouse the elders Smile

Thanks Michael ... but that's not working either ... here's my debug. It could be the fact that this is ODBC and not Active Record? This blasted Windows Server and it's proprietary flat file database/ODBC has been a nuisance.

Code:
---DATA---
HTTP/1.1 200 OK
Date: Mon, 01 Dec 2008 21:19:34 GMT
Server: Apache/2.2.8 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Content-Length: 1364
Connection: close
Content-Type: text/xml

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Array to string conversion</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 234</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Illegal offset type</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1220</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Illegal offset type</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1224</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Illegal offset type</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1228</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  </p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1326</p>

</div>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodResponse>
<params>
<param>
<value>
</value>
</param>
</params>
</methodResponse>
---END DATA---


The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.

#7
[eluser]skattabrain[/eluser]
my request ...
Code:
function customerlist()
    {    
        $this->load->helper('url');
        $this->load->library('xmlrpc');
        
        $this->xmlrpc->server('mydomainhere.com/index.php/get_customer', 84);
        $this->xmlrpc->method('Customerlist');
        
        $this->xmlrpc->set_debug(TRUE);
        
        $request = array('');
        $this->xmlrpc->request($request);    
        
        if ( ! $this->xmlrpc->send_request())
        {
            echo $this->xmlrpc->display_error();
        }
        else
        {
            echo '<pre>';
            print_r($this->xmlrpc->display_response());
            echo '</pre>';
        }
                
    }

my server ...

Code:
class Get_customer extends Controller {

    function index()
    {
        $this->load->library('xmlrpc');
        $this->load->library('xmlrpcs');
        
        $this->xmlrpc->set_debug(TRUE);
        
        $config['functions']['Customer'] = array('function' => 'Get_customer.customer');
        $config['functions']['Customerlist'] = array('function' => 'Get_customer.customerlist');
        
        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
    }
    
    function customerlist($request)
    {
        
        // This is a query via ODBC
        $query = $this->db->query("SELECT * FROM AR_Customer");
        
        // Give the request back
        return $this->xmlrpc->send_response($query->result_array());
        
    }

}

#8
[eluser]skattabrain[/eluser]
here is what the ODBC $query looks like (var_dump)

Code:
object(CI_DB_odbc_result)#12 (7) {
  ["conn_id"]=>
  resource(30) of type (odbc link persistent)
  ["result_id"]=>
  resource(31) of type (odbc result)
  ["result_array"]=>
  array(0) {
  }
  ["result_object"]=>
  array(0) {
  }
  ["current_row"]=>
  int(0)
  ["num_rows"]=>
  int(59)
  ["row_data"]=>
  NULL
}

In order to use it in a normal controller/view scenrio it's same there anyways...

Code:
echo '<ul>';
        foreach($query->result() as $row)
        {
            echo '<li>'.anchor('get_customer/profile/'.$row->CustomerNo, $row->CustomerName).' </li>';            
        }
        echo '</ul>';

#9
[eluser]skattabrain[/eluser]
Any ideas? I need to get this accomplished today. Any assistance is appreciated.

#10
[eluser]skattabrain[/eluser]
Here is where I'm at ... I have no idea what is wrong with the array I'm building here (building it because I'm no sure sure the ODBC query is the expected format for XML-RPC.

Code:
$query = $this->db->query("SELECT * FROM AR_Customer");
        
        $myarray = array();
        
        foreach($query->result() as $row)
        {
            $myarray[$row->CustomerNo] = array(
                'CustomerNo' => $row->CustomerNo,
                'CustomerName' => $row->CustomerName
                );
        }        
    
        $response = array($myarray, 'array');
        
        // Give the request back
        return $this->xmlrpc->send_response($response);

Generates this error (shown from the client with debugging on)

The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.

Code:
---DATA---
HTTP/1.1 200 OK
Date: Tue, 02 Dec 2008 15:32:55 GMT
Server: Apache/2.2.8 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Connection: close
Content-Type: text/html

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined offset:  0</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1345</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1379</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  reset() [<a href='function.reset'>function.reset</a>]: Passed variable is not an array or object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1380</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Variable passed to each() is not an array or object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1382</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  </p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1326</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined offset:  1</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1345</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1379</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  reset() [<a href='function.reset'>function.reset</a>]: Passed variable is not an array or object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1380</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Variable passed to each() is not an array or object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1382</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  </p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1326</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined offset:  2</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1345</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1379</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  reset() [<a href='function.reset'>function.reset</a>]: Passed variable is not an array or object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1380</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Variable passed to each() is not an array or object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1382</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  </p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1326</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined offset:  3</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1345</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1379</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

etc ...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.