After discovering that the PHP WDDX functions dont appear to support recordsets, i modified the ODBCSocketServer PHP code posted here a while back to deal with the XML used by WDDX. I've pasted the code (WDDXrs.php) below. If it gets mangled in the post, email me and i'll send you a copy. If enough people show interest, i might considered beefing it up a little, add some decent error checking and maintain. To use the WDDXrs object, all the calls are the same as for ODBCSocketServer object.
regards,
<?
//
// based on the OdbcSocketServer code from phpbuilder.net
// then heavily modified to cope with WDDX recordset packets, not
// the XML produced by ODBCss
//
// Does not deal with other WDDX datatypes, e.g. int, string, etc.
//
// Currently only recognizes string and number types in the returned recordset,
// but it would be trivial to add support for them
// (see the select/case statement in _startElement)
class WDDXrs
{
var $debug = 0;
var $xml="";
var $error="";
var $recordset=null;
var $bof = true;
var $eof = true;
var $recordcount=0;
var $rowCount=0;
var $currentrow = -1;
var $currentcol = -1;
var $fieldnames;
var $fieldcount=0;
var $cfn='';
function execute($URL) {
// This function attempts to retrieve a URL that in theory returns a WDDX recordset
// If it returns false check the $Error variable to see what went wrong.
// First reset current objects
$this->xml="";
$this->error="";
$this->recordset=null;
// This will set $this->XML if a succesful
// connection and exchange takes place.
if (!$this->_sendURL($URL)) return false;
// parse the resultant XML This will set the
// $this->_result variable
$this->_parseXML();
$this->_initRecordset();
return $this->_result;
} //execURL
function _parseXML()
{
$this->parser = xml_parser_create();
xml_set_element_handler($this->parser, "startElement", "endElement");
xml_set_character_data_handler($this->parser, "characterData");
xml_parser_set_option ($this->parser,XML_OPTION_CASE_FOLDING,$this->CaseFolding);
xml_set_object($this->parser,&$this);
// We are going to presume everything will be OK
// If there are any problems then this will be reset.
// by one of the callback functions
$this->_result = true;
if (!xml_parse($this->_parser, $this->XML)) {
$this->result=false;
$this->Error=sprintf("XML Parse Error: %s at line %d",
xml_error_string(xml_get_error_code($this->parser)),
xml_get_current_line_number($this->_parser));
}
xml_parser_free($this->_parser);
}
function _sendURL($wddxurl)
{
$wddxdata = fopen($wddxurl , 'r');
if (!$wddxdata)
{
//contruct ErrorString string to return
$this->XML = "<?xml version=\"1.0\"?>\r\n<result state=\"failure\">\r\n<ErrorString>$errstr</ErrorString>\r\n</result>\r\n";
$this->Error=$errstr;
$this->_result=false;
$retval=false;
}
else
{
$result = fread ($wddxdata , 9068);
fclose($wddxdata);
$this->XML=$result;
$retval=true;
} // if
return $retval;
} // _sendURL
function _startElement($parser, $name, $attribs)
{
wddx record sets are returned column by column , not row by row!
$this->currenttag = strtolower($name);
switch ($this->currenttag){
case "field":
the start of each field tag significies the start of a new COLUMN of data, one element
for each row of the table.
$this->currentcol++;
$this->currentrow=-1;
break;
case number:
add current value to current COLUMN of data
$this->currentrow++;
if ($debug) {print 'n';}
break;
case string:
add current string to current COLUMN of data for this
$this->currentrow++;
if ($debug) {print 's';}
break;
case "recordset":
$this->rowCount = $attribs["rowCount"];
$this->_result=($this->rowCount>0);
$fields = split (',' , $attribs["fieldNames"]) ;
$this->fieldnames = $fields;
break;
case "error":
// this is text so just set the result
$this->result=0;
break;
}
}
function _endElement($parser, $name)
{
// not used here
switch($this->_currenttag){
is this actually necessary ?
case "field":
$currentrow = -1;
break;
}
return;
}
function _characterData($parser, $data)
{
// need to save this bit of data into our growing array..
// need to make sure that the data we are processing is INSIDE a set of column tags
// and not the cruft with tags that contain nothing but other tags
if ( $data
&& preg_match('/string|number/' , $this->_currenttag)
&& !preg_match('/\n/' , $data))
{
$this->recordset[$this->currentrow][$this->fieldnames[$this->currentcol]] = $data;
if ($debug)
{
print 'R:' . $this->currentrow . ' C:' . $this->currentcol .' = ';
print '(' . $this->fieldnames[$this->currentcol] . ')';
print '!' . $this->recordset[$this->currentrow][$this->fieldnames[$this->currentcol]];
print '!<br>';
}
}
} // end of character data
//
// Most of the code below this point is unmodified from the original ODBCss code from phpbuilder.net
//
/// Recordset Related functions
function _initRecordset() {
$this->recordcount = count($this->recordset);
$this->fieldcount = count($this->fieldnames);
$this->_currentRow = 0;
} // _initRecordset()
function GetField( $field = '')
{
return $this->recordset[$this->_currentRow][$field] ;
}
function GetNumOfRows ()
{
return count($this->recordset);
}
function GetNumOfFields ()
{
return count($this->fieldnames);
}
function nextRow(){
$this->currentRow++ ;
$this->setCurrentRecord();
}
function moveNext(){
$this->nextRow();
}
function prevRow(){
$this->currentRow-- ;
$this->setCurrentRecord();
}
function movePrev(){
$this->prevRow();
}
function firstRow() {
$this->currentRow = 0 ;
$this->setCurrentRecord();
}
function moveFirst() {
$this->firstRow();
}
function lastRow() {
$this->currentRow= $this->recordcount -1 ;
$this->setCurrentRecord();
}
function moveLast() {
$this->lastRow();
}
function moveRow($rowNumber = 0) {
$this->currentRow=$rowNumber;
$this->setCurrentRecord();
}
function getfieldnames() {
return $this->fieldnames;
}
function _setCurrentRecord() {
if (0 == $this->recordcount){
$this->EOF = true;
$this->BOF = true;
}else if ($this->_currentRow > ($this->recordcount - 1)){
$this->EOF = true;
$this->BOF = false;
$this->_currentRow = $this->recordcount;
}else if ($this->currentRow < 0){
$this->BOF=true;
$this->EOF=false;
$this->currentRow = -1;
}else{
$this->EOF = false;
$this->BOF = false;
$record=$this->Recordset[$this->_currentRow];
foreach ($this->fieldnames as $fieldname ) {
if ($this->CaseFolding):
$fieldname=strtoupper($fieldname);
endif;
$this->$fieldname =$record[$fieldname];
}
/
while (list($key, $value) = each ($record)) {
$this->$key = $value;
}// while
/
} // if
} // _setCurrentRecord
function errorMsg() {
return $this->Error;
}
}
?>