php 导出xml数据,使用php从xml中的mysql导出数据

我试图使用PHP将数据从mysql数据库导出为特定的xml格式.

我是这样创造的.

如果我喜欢这个,我得到xml中$string的正确输出.

$string = <<<_xml_>

2010-07-20T00:00:00Z

id

title

description

Comma,Separated,Keywords,Go,Here

Name Of site

http://www.domain.com/path/to/videos/

http://www.domain.com/path/to/thumbnails/

20

640

480

marta_123.flv

marta.jpg

20

640

480

jenna_123.flv

jenna.jpg

123

640

480

kathy_123.flv

kathy.jpg

_XML_;

$xml = new SimpleXMLElement($string);

Header('Content-type: text/xml');

echo $xml->asXML();

?>

但是,如果我尝试从db中提取值并放入相同的层次结构,它不会在xml中输出数据.像这样

$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_>2010-07-20T00:00:00Z';

while ($row = mysql_fetch_array($result)) {

$id=$row['id'];

$title=$row['title'];

$string .=''.$id.'';

$string .='

'.$title.'';

}

$string .='_XML_';

$xml = new SimpleXMLElement($string);

Header('Content-type: text/xml');

echo $xml->asXML();

?>

其输出在页面源中显示<<<< XML.

我做错了什么.

我想要的是使用php将数据从mysql导出到xml.

谢谢你的时间

解决方法:

试试这段代码:

$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 = '2010-07-20T00:00:00Z';

while ($row = mysql_fetch_array($result)) {

$id=$row['id'];

$title=$row['title'];

$string .=''.$id.'';

$string .='

'.$title.'';

}

$string .='';

$xml = new SimpleXMLElement($string);

Header('Content-type: text/xml');

echo $xml->asXML();

?>

标签:php,mysql,xml

来源: https://codeday.me/bug/20190629/1329312.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值