从xml文件检索后,将不同行的数据插入mysql php

从xml文件检索后,将不同行的数据插入mysql php,php,mysql,xml,arrays,Php,Mysql,Xml,Arrays,test.xml <?xml version="1.0" encoding="ISO-8859-1"?> <propertyList> <business type="food"> <listingAgent id="1"> <name>Spiro Abelas</name> <email>spiro@abelas.com.au</email> </listingA

test.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<propertyList>
  <business  type="food">
  <listingAgent id="1">
    <name>Spiro Abelas</name>
    <email>spiro@abelas.com.au</email>
  </listingAgent>
 </business>
 <business  type="food">
  <listingAgent id="2">
    <name>andy</name>
    <email>andy@abelas.com.au</email>
  </listingAgent>
 </business>
</propertyList>
表格结构

foreach($xml->business as $row)
{
  $business_type = $row->attributes()->type;
  $id = $row->listingAgent->attributes()->id;
  $name = $row->listingAgent->name;
  $email = $row->listingAgent->email;
  mysql_query('INSERT INTO table…');
}

我想将这样的数据插入表中

但我不知道如何从数组中检索数据并插入到多行中


所以请告诉我如何整理它

可能重复的感谢回复,但我得到了对非对象上成员函数attributes()的错误调用
     SimpleXMLElement Object
(
[business] => Array
(
[0] => SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [type] => food
        )
    [listingAgent] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [id] => 1
                )
            [name] => spiro
            [email] => spiro@abelas.com.au
        )
)
[1] => SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [type] => food
        )
    [listingAgent] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [id] => 2
                )
            [name] => andy
            [email] => andy@abelas.com.au
        )
)))
foreach($xml->business as $row)
{
  $business_type = $row->attributes()->type;
  $id = $row->listingAgent->attributes()->id;
  $name = $row->listingAgent->name;
  $email = $row->listingAgent->email;
  mysql_query('INSERT INTO table…');
}