Source for file toxmlrpc.inc.php
Documentation is available at toxmlrpc.inc.php
* Helper functions to convert between ADODB recordset objects and XMLRPC values.
* Uses John Lim's AdoDB and Edd Dumbill's phpxmlrpc libs
* @author Daniele Baroncelli
* @copyright (c) 2003-2004 Giunta/Baroncelli. All rights reserved.
* @todo some more error checking here and there
* @todo document the xmlrpc-struct used to encode recordset info
* @todo verify if using xmlrpc_encode($rs->GetArray()) would work with:
* Include the main libraries
require_once('xmlrpc.inc');
if (!defined('ADODB_DIR')) require_once('adodb.inc.php');
* Builds an xmlrpc struct value out of an AdoDB recordset
// put it all together and build final xmlrpc struct
$xmlrpcrs =
new xmlrpcval ( array(
* Builds an xmlrpc struct value describing an AdoDB recordset
$numfields =
$adodbrs->FieldCount();
$numrecords =
$adodbrs->RecordCount();
// build structure holding recordset information
for ($i =
0; $i <
$numfields; $i++
) {
$fld =
$adodbrs->FetchField($i);
$fieldarray["name"] =
new xmlrpcval ($fld->name);
$fieldarray["type"] =
new xmlrpcval ($fld->type);
if (isset
($fld->max_length))
$fieldarray["max_length"] =
new xmlrpcval ($fld->max_length, "int");
if (isset
($fld->not_null))
$fieldarray["not_null"] =
new xmlrpcval ($fld->not_null, "boolean");
if (isset
($fld->has_default))
$fieldarray["has_default"] =
new xmlrpcval ($fld->has_default, "boolean");
if (isset
($fld->default_value))
$fieldarray["default_value"] =
new xmlrpcval ($fld->default_value);
$fieldstruct[$i] =
new xmlrpcval ($fieldarray, "struct");
$fieldcount =
new xmlrpcval ($numfields, "int");
$recordcount =
new xmlrpcval ($numrecords, "int");
$sql =
new xmlrpcval ($adodbrs->sql);
$fieldinfo =
new xmlrpcval ($fieldstruct, "array");
$header =
new xmlrpcval ( array(
"fieldcount" =>
$fieldcount,
"recordcount" =>
$recordcount,
"fieldinfo" =>
$fieldinfo
* Builds an xmlrpc struct value out of an AdoDB recordset
* (data values only, no data definition)
$numfields =
$adodbrs->FieldCount();
// build structure containing recordset data
// This should work on all cases of fetch mode: assoc, num, both or default
if ($adodbrs->fetchMode ==
'ADODB_FETCH_BOTH' ||
count($adodbrs->fields) ==
2 *
$adodbrs->FieldCount())
for ($i =
0; $i <
$numfields; $i++
)
if ($adodbrs->fields[$i] ===
null)
$columns[$i] =
new xmlrpcval ('');
$columns[$i] =
xmlrpc_encode ($adodbrs->fields[$i]);
foreach ($adodbrs->fields as $val)
$columns[] =
new xmlrpcval ('');
$columns[] =
xmlrpc_encode ($val);
$rows[] =
new xmlrpcval ($columns, "array");
$body =
new xmlrpcval ($rows, "array");
* Returns an xmlrpc struct value as string out of an AdoDB recordset
* Given a well-formed xmlrpc struct object returns an AdoDB object
* @todo add some error checking on the input value
// rebuild column information
$header =
$xmlrpcval->structmem('header');
$numfields =
$header->structmem('fieldcount');
$numfields =
$numfields->scalarval();
$numrecords =
$header->structmem('recordcount');
$numrecords =
$numrecords->scalarval();
$sqlstring =
$header->structmem('sql');
$sqlstring =
$sqlstring->scalarval();
$fieldinfo =
$header->structmem('fieldinfo');
for ($i =
0; $i <
$numfields; $i++
) {
$temp =
$fieldinfo->arraymem($i);
$fld =
new ADOFieldObject();
while (list
($key,$value) =
$temp->structeach()) {
if ($key ==
"name") $fld->name =
$value->scalarval();
if ($key ==
"type") $fld->type =
$value->scalarval();
if ($key ==
"max_length") $fld->max_length =
$value->scalarval();
if ($key ==
"not_null") $fld->not_null =
$value->scalarval();
if ($key ==
"has_default") $fld->has_default =
$value->scalarval();
if ($key ==
"default_value") $fld->default_value =
$value->scalarval();
// fetch recordset information into php array
$body =
$xmlrpcval->structmem('body');
for ($i =
0; $i <
$numrecords; $i++
) {
$data_array[$i]=
array();
$xmlrpcrs_row =
$body->arraymem($i);
for ($j =
0; $j <
$numfields; $j++
) {
$temp =
$xmlrpcrs_row->arraymem($j);
$data_array[$i][$j] =
$temp->scalarval();
// finally build in-memory recordset object and return it
$rs =
new ADORecordSet_array();
$rs->InitArrayFields($data_array,$fields_array);
Documentation generated on Sun, 09 Mar 2008 23:53:38 -0300 by phpDocumentor 1.4.0