The preceding mysql. php is a encapsulated mysql database function in Singleton mode. Therefore, the static method mysql: getObject () is used to retrieve the object. the code is very simple, as shown below :? Mysql. php in front of phpinclude... is the encapsulated mysql database function in Singleton mode. Therefore, the object is the static method mysql: getObject ();
The code is as follows:
query("SELECT * FROM post");$xml = new XMLWriter();$xml->openUri('hello.xml'); // or 'php://output'$xml->setIndentString(' ');$xml->setIndent(true);// start$xml->startDocument('1.0', 'UTF-8');//
$xml->startElement('rss');$xml->writeAttribute('version', '2.0');//
$xml->startElement('channel');// title$xml->startElement('title');$xml->text('title');$xml->endElement();// link$xml->startElement('link');$xml->text('http://foodstory.me/post/');$xml->endElement();// description$xml->startElement('description');$xml->text('');$xml->endElement();// language$xml->startElement('language');$xml->text('zh-cn');$xml->endElement();// category$xml->startElement('category');$xml->text('IT');$xml->endElement();// copyright$xml->startElement('copyright');$xml->text('copyright 2011 foodstory.me');$xml->endElement();// for itemwhile ($row = $mysql->fetch()) { $xml->startElement('item'); // title $xml->startElement('title'); $xml->text($row['title']); $xml->endElement(); // link $xml->startElement('link'); $xml->text('http://foodstory.me/post/' . $row['id'] . '.html'); $xml->endElement(); // description $xml->startElement('description'); $xml->text($row['text']); $xml->endElement(); // pubDate $xml->startElement('pubDate'); $xml->text(date('D, d M Y H:i:s T', $row['time'])); $xml->endElement(); // category tag author need to write .over $xml->endElement(); // item }$xml->endElement(); // channel$xml->endElement(); // rss$xml->endDocument();// $xml->flush();?>
The parameter of the openUri ('') method can be a file, so xml data is written to this file or php: // output is output to the buffer, and then flush is output to the page.
Link to this article:
Add to favorites ^ please keep the tutorial address.