-6

我想将 XML 数据插入数据库,但有些字段没有插入 我有这样的 XML 数据

SimpleXMLElement Object (
    [person-id] => 4562
    [name] => gopi 
    [category] => working 
    [lead-commission] => SimpleXMLElement Object ( )
    [expire-date] => SimpleXMLElement Object ( )
    [manufactur-date] => SimpleXMLElement Object ( )
    [type] => medicine [sale-commission] => 1.00%
)

我要插入数据库的代码

foreach($xml->link AS $value)
{
    $data['person-id']= $value->{'person-id'};
    $data['name']= $value->{'name'};  
    $data['category']= $value->{'category'};
    $data['lead-commission']= $value->{'lead-commission'};
    $data['expire-date']= $value->{'expire-date'};
    $data['manufacture-date']= $value->{'manufactur-date'};
    $data['type']= $value->{'type'};
    $data['sale-commission']= $value->{'sale-commission'};
}

但是我无法在我的数据库中插入lead-commissionexpire-datemanufactur-date,你能帮我如何插入这些字段吗?

4

1 回答 1

-1

您可以使用此函数并将 XML 转换为 PHP 数组

http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/

然后使用“ print_r()”查看字段和数组结构。相应地插入数据。

希望提供的链接有帮助

于 2013-01-07T06:06:38.110 回答