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

#11
[eluser]Nick Husher[/eluser]
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);

The issue here is that you're assigning a type of Array, but the data that you are sending is not contiguously indexed. For example, if you have customer numbers of [0,3,9,41,42,43,121], your array will look like [0=>"Customer 0", 1=>undefined, 2=>undefined ... 9=>"Customer 9" ...]. When the loop that's cycling over your array gets to index 1, it dies, becuase index 1 is undefined.

You can find the relevant code in your CI project under /system/libraries/Xmlrpc.php on line 1341. Here's what it looks like:

Code:
// array
$rs .= "<array>\n<data>\n";
for($i=0; $i < sizeof($val); $i++)
{
  $rs .= $this->serializeval($val[$i]);
}
$rs.="</data>\n</array>\n";
break;

You can see that it's doing a linear iteration of your array, which will fail if your indexes aren't contiguous.

#12
[eluser]skattabrain[/eluser]
Hmmm, if I understood you correctly ... using a simple counter starting at zero for $myarray is all I really need to do.

That's failing too ...

Code:
$query = $this->db->query("SELECT * FROM AR_Customer");
        
        $counter = 0;
        $myarray = array();
        
        foreach($query->result() as $row)
        {
            $myarray[$counter] = array(
                'CustomerNo' => $row->CustomerNo,
                'CustomerName' => $row->CustomerName,
                );
            
            $counter++;
        }
        
        
        
        $response = array($myarray, 'array');

        
        
        return $this->xmlrpc->send_response($response);

returns ...

[code]
---DATA---
HTTP/1.1 200 OK
Date: Tue, 02 Dec 2008 16:48:30 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: Warning</p>
<p>Message: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</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: htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</p>

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



on and on ....

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

etc....

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.

#13
[eluser]Nick Husher[/eluser]
I think your inner loop isn't defining a data type. It's attempting to typecast your array into a string and failing.


Code:
$query = $this->db->query("SELECT * FROM AR_Customer");

$counter = 0;
$myarray = array();

foreach($query->result() as $row) {

    // you need to define a data type
    $myarray[$counter] = array(array(
    'CustomerNo' => $row->CustomerNo,
    'CustomerName' => $row->CustomerName,
    ), 'struct');

    $counter++;
}

$response = array($myarray, 'array');

return $this->xmlrpc->send_response($response);

#14
[eluser]skattabrain[/eluser]
Hmmm ... thanks Nick, still not working, but the data is passing through ... i removed customer names in this result ...
Code:
---DATA---
HTTP/1.1 200 OK
Date: Tue, 02 Dec 2008 18:40:29 GMT
Server: Apache/2.2.8 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Content-Length: 12550
Connection: close
Content-Type: text/xml

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>AESTH</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>0_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>ALEXA</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>1_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>ALMAN</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>2_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>ASC</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>3_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>ASECRET</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>4_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>ATMED</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>5_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BALL</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>6_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BARBJ</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>7_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BAYSH</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>8_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BEANS</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>9_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BELLAV</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>10_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BLOOM</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>11_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BMSM</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>12_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>BMSR</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>13_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>CHRYS</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>14_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>DRD</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>15_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>ESSE</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>16_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>ESSEN</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>17_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>GMBB</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>18_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>GMRET</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>19_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>HOUP</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>20_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>HPSBB</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>21_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>HPSR</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>22_HIDE_NAME</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>JOSEP</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>23_HIDE_NAME</string>

etc ....

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.

#15
[eluser]Nick Husher[/eluser]
What's the tail end of your xmlrpc look like? The whole thing should look like a very long version of this:

Code:
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodResponse>
    <params>
        <param>
            <value>
                <array>
                    <data>
                        <value>
                            <struct>
                                <member>
                                    <name>CustomerNo</name>
                                    <value>
                                        <string>AESTH</string>
                                    </value>
                                </member>
                                <member>
                                    <name>CustomerName</name>
                                    <value>
                                        <string>0_HIDE_NAME</string>
                                    </value>
                                </member>
                            </struct>
                        </value>
                    </data>
                </array>
            </value>
        </param>
    </params>
</methodResponse>

#16
[eluser]skattabrain[/eluser]
Code:
<string>Evelyn Mak</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>LAURIA</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>Lauria Lacayo</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>SCOTT</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>Scott Watt</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>TANAG</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>Tana Grenz</string>
</value>
</member>
</struct></value>
<value>
<struct>
<member>
<name>CustomerNo</name>
<value>
<string>TERESAD</string>
</value>
</member>
<member>
<name>CustomerName</name>
<value>
<string>Teresa Dutton</string>
</value>
</member>
</struct></value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>

#17
[eluser]skattabrain[/eluser]
it's too large to post complete ... and LIMIT isn't working on this ODBC query.

#18
[eluser]skattabrain[/eluser]
the XML is valid btw

#19
[eluser]skattabrain[/eluser]
moved the big question here - http://ellislab.com/forums/viewthread/98676/


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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