脚本宝典收集整理的这篇文章主要介绍了使用php从xml中的mysql导出数据,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我是这样创造的.
<?PHP $string = <<<_XML_ <videos> <updated>2010-07-20T00:00:00Z</updated> <video> <id>id</id> <tITle>title</title> <description>description</description> <tags>Comma,Separated,Keywords,Go,Here</tags> <paysite>Name Of site</paysite> <clip_url>http://www.domain.COM/path/to/videos/</clip_url> <screen_url>http://www.domain.com/path/to/thumbnails/</screen_url> <clips> <clip> <duration>20</duration> <width>640</width> <height>480</height> <flv>marta_123.flv</flv> <screens> <screen>marta.jpg</screen> </screens> </clip> <clip> <duration>20</duration> <width>640</width> <height>480</height> <flv>jenna_123.flv</flv> <screens> <screen>jenna.jpg</screen> </screens> </clip> <clip> <duration>123</duration> <width>640</width> <height>480</height> <flv>kathy_123.flv</flv> <screens> <screen>kathy.jpg</screen> </screens> </clip> </clips> </video> </videos> _XML_; $xml = new SimpleXMLElement($string); Header('Content-tyPE: text/xml'); echo $xml->asXML(); ?>
但是,如果我尝试从db中提取值并放入相同的层次结构,它不会在xml中输出数据.像这样
<?PHP $dbh=MysqL_connect($localhost,$username,$password) or die ('I cannot connect to the database because: ' . MysqL_error()); $result = MysqL_query("SELECT * From 12345_flv.flv WHERE enabled = '1' ORDER BY id DESC") or die('Could not connect: ' . MysqL_error()); $string = '<<<_XML_<videos><updated>2010-07-20T00:00:00Z</updated><video>'; while ($row = MysqL_fetch_array($result)) { $id=$row['id']; $title=$row['title']; $string .='<id>'.$id.'</id>'; $string .='<title>'.$title.'</title>'; } $string .='</video></videos>_XML_'; $xml = new SimpleXMLElement($string); Header('Content-type: text/xml'); echo $xml->asXML(); ?>
其输出在页面源中显示<<<< XML. 我做错了什么.
我想要的是使用PHP将数据从MysqL导出到xml.
谢谢你的时间
<?PHP $dbh=MysqL_connect($localhost,$password) or die ('I cannot connect to the database because: ' . MysqL_error()); $result = MysqL_query("SELECT * From 12345_flv.flv WHERE enabled = '1' ORDER BY id DESC") or die('Could not connect: ' . MysqL_error()); $string = '<videos><updated>2010-07-20T00:00:00Z</updated><video>'; while ($row = MysqL_fetch_array($result)) { $id=$row['id']; $title=$row['title']; $string .='<id>'.$id.'</id>'; $string .='<title>'.$title.'</title>'; } $string .='</video></videos>'; $xml = new SimpleXMLElement($string); Header('Content-type: text/xml'); echo $xml->asXML(); ?>
以上是脚本宝典为你收集整理的使用php从xml中的mysql导出数据全部内容,希望文章能够帮你解决使用php从xml中的mysql导出数据所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。