Re: mysql_fetch_xml
| From: | Brian Moon | Date: | Thu, 23 Aug 2001 21:10:33 +0000 |
| Subject: | Re: mysql_fetch_xml | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-64189@lists.php.net to get a copy of this message | ||
This is a very neat function. I may be able to use it. Having said that I
think it is best left as a userland function.
Brian Moon
------------------------------------------
dealnews.com, Inc.
Makers of dealnews & dealmac
http://dealnews.com/ | http://dealmac.com/
----- Original Message -----
From: "Eliot Shepard" <eliot.shepard@the451.com>
To: <php-dev@lists.php.net>
Sent: Thursday, August 23, 2001 3:38 PM
Subject: [PHP-DEV] mysql_fetch_xml
> 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
> eliot.shepard@the451.com
>
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>