gpt4 book ai didi

php - 根据 PHP 名称/值对数组将值输入 MySql 数据库

转载 作者:行者123 更新时间:2023-11-30 01:37:56 25 4
gpt4 key购买 nike

我有以下数组:

      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 上现有且匹配的数据库中。

这里~~~> Gallops 是数据库名称,Details、Vaccination、Deworming 和 Weight 是表格。

这是我的 PHP 脚本,在向它传递 XML 文件后,我从中获取上述值。

              <?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。我需要一个起点或一个解决方案。将不胜感激。

最佳答案

关于php - 根据 PHP 名称/值对数组将值输入 MySql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16602434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com