2013-05-17 55 views
0

我有以下阵列:输入值到MySQL数据库

 SimpleXMLElement Object 
    (
    [@attributes] => Array 
    (
     [name] => Gallops 
    ) 

[table] => Array 
    (
     [0] => SimpleXMLElement Object 
      (
       [@attributes] => Array 
        (
         [name] => Details 
        ) 

       [row] => SimpleXMLElement Object 
        (
         [col] => Array 
          (
           [0] => 1 
           [1] => Ggvbbvhh 
           [2] => Vvb 
           [3] => Bnb 
           [4] => SimpleXMLElement Object 
            (
             [@attributes] => Array 
              (
               [name] => Owner 
              ) 

            ) 

           [5] => Marwari horse 
           [6] => Gender 
           [7] => 16-May-2013 
           [8] => SimpleXMLElement Object 
            (
             [@attributes] => Array 
              (
               [name] => Notes 
              ) 

            ) 

           [9] => Nature 
           [10] => Color 
           [11] => SimpleXMLElement Object 
            (
             [@attributes] => Array 
              (
               [name] => Sire 
              ) 

            ) 

           [12] => SimpleXMLElement Object 
            (
             [@attributes] => Array 
              (
               [name] => Dam 
              ) 

            ) 

           [13] => 0.0hh 
           [14] => SimpleXMLElement Object 
            (
             [@attributes] => Array 
              (
               [name] => Foaled 
              ) 

            ) 

           [15] => 16-May-2013 
           [16] => null 
          ) 

        ) 

      ) 

     [1] => SimpleXMLElement Object 
      (
       [@attributes] => Array 
        (
         [name] => Vaccination 
        ) 

       [row] => SimpleXMLElement Object 
        (
         [col] => Array 
          (
           [0] => 1 
           [1] => Pending 
           [2] => Ggvbbvhh 
           [3] => Rabies 
           [4] => 16-5-2013 
           [5] => 17:22 
          ) 

        ) 

      ) 

     [2] => SimpleXMLElement Object 
      (
       [@attributes] => Array 
        (
         [name] => DeWorming 
        ) 

       [row] => SimpleXMLElement Object 
        (
         [col] => Array 
          (
           [0] => 1 
           [1] => Pending 
           [2] => Ggvbbvhh 
           [3] => Large strongyles 
           [4] => 16-5-2013 
           [5] => 17:22 
          ) 

        ) 

      ) 

     [3] => SimpleXMLElement Object 
      (
       [@attributes] => Array 
        (
         [name] => Weight 
        ) 

       [row] => SimpleXMLElement Object 
        (
         [col] => Array 
          (
           [0] => 1 
           [1] => Ggvbbvhh 
           [2] => 32.27lbs 
           [3] => 2013-05-16 
          ) 

        ) 

      ) 

    ) 

) 
    @attributes => Array 
    row => 
    @attributes => Array 
    row => 
    @attributes => Array 
    row => 
    @attributes => Array 
    row => 

我寻找一个脚本这有助于我插入这些值到现有的和MySQL的匹配DB 。

Here ~~~> Gallops是DB名称,详情,接种疫苗,驱虫和体重都是表格。

这是我从哪里获得上述值后,我通过它的XML文件的PHP脚本。

   <?php 
       echo "<pre>"; 
       $xml = simplexml_load_file("DB355404040101391.xml"); 
        print_r($xml); 
        echo "</pre>"; 
        echo "<pre>"; 
        foreach($xml->children() as $item){ 
         $arr = get_object_vars($item); 
         foreach($arr as $key=>$value){ 
          echo "$key => $value" . PHP_EOL;    
         } 
        } 
        echo "</pre>"; 
       ?> 

下面是XML文件:

<?xml version="1.0" encoding="utf-8"?> 
    <database name='anahuacForm'> 
    <table name='Details'> 
     <row> 
     <col name='_id'>1</col> 
     <col name='IDno'>Ggvbbvhh</col> 
     <col name='GIDno'>Vvb</col> 
     <col name='Name'>Bnb</col> 
     <col name='Owner'></col> 
     <col name='Breed'>Marwari horse</col> 
     <col name='Gender'>Gender</col> 
     <col name='Date'>16-May-2013</col> 
     <col name='Notes'></col> 
     <col name='Nature'>Nature</col> 
     <col name='Color'>Color</col> 
     <col name='Sire'></col> 
     <col name='Dam'></col> 
     <col name='Height'>0.0hh</col> 
     <col name='Foaled'></col> 
     <col name='Acquired'>16-May-2013</col> 
     <col name='image'>null</col> 
    </row> 
</table> 
<table name='Vaccination'> 
    <row> 
     <col name='_id'>1</col> 
     <col name='flag'>Pending</col> 
     <col name='HVID'>Ggvbbvhh</col> 
     <col name='Vname'>Rabies</col> 
     <col name='Vdate'>16-5-2013 </col> 
     <col name='Vtime'>17:22</col> 
    </row> 
</table> 
<table name='DeWorming'> 
    <row> 
     <col name='_id'>1</col> 
     <col name='flag'>Pending</col> 
     <col name='DVID'>Ggvbbvhh</col> 
     <col name='Dname'>Large strongyles</col> 
     <col name='Ddate'>16-5-2013 </col> 
     <col name='Dtime'>17:22</col> 
    </row> 
</table> 
<table name='Weight'> 
    <row> 
     <col name='_id'>1</col> 
     <col name='HWID'>Ggvbbvhh</col> 
     <col name='Wmeasure'> 32.27lbs</col> 
     <col name='WDate'>2013-05-16</col> 
    </row> 
</table> 

我可以去一个简单的方法也一样,在那里我可以直接进入XML到MySQL。我需要一个起点或一个解决方案。将不胜感激。

+0

更新XML这将是太好得到回答,而不是调试语法 – Sundar

回答