I have written a simple PHP function which returns all result rows
associated with a mysql query as an XML document. I needed this to
facilitate XSLT presentation of database records.

I was thinking about reimplementing the function in C and contributing
it to php_mysql.c. Would there be any interest in incorporating this
into the codebase?

Eliot


The PHP function:

<?php

function mysql_fetch_xml($result) {
// turn an mysql query result into an xml document.

    $retval = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
    $retval .= "<result>";

    while ($row = mysql_fetch_assoc($result)) {
        $retval .= "<row>";
        while(list($key, $value) = each($row)) {
            $retval .= "<$key>$value</$key>";
        }
        $retval .= "</row>";
    }

    $retval .= "</result>";

    return $retval;
}

?>

Here's a usage example:

$rows   = mysql_query($query, $dblink);
$xml    = mysql_fetch_xml($rows);

$parser = xslt_create();
$xsl    = join ('', file ('./present_rows.xsl'));
xslt_process($xsl, $xml, $result);
xslt_free($parser);

print $result;


--
Eliot Shepard
[EMAIL PROTECTED]



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to