当我使用普通 xml 树结构将数据插入数据库时,数据已成功插入,但是当我尝试使用不同的 xml 结构将数据插入数据库时,它没有给我任何错误,但同时创建了字段,但我不能可视化表格中的内容,
<?xml version="1.0"?>
<xml>
<draw>
<candelete>yes</candelete>
<forpayroll>no</forpayroll>
<name>hello</name>
</draw>
</xml>
以上xml格式成功将数据插入mysql数据库
以下 xml 格式不允许我将数据插入 mysql 数据库
<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<STATUS>1</STATUS>
</HEADER>
<BODY>
<DESC>
</DESC>
<DATA>
<TALLYMESSAGE>
<LEDGER NAME="Dena" RESERVEDNAME="" ID="2240" REQNAME="dena">
<PARENT TYPE="String">Bank Accounts</PARENT>
<TAXTYPE TYPE="String">Others</TAXTYPE>
<ISBILLWISEON TYPE="Logical">No</ISBILLWISEON>
<ISCOSTCENTRESON TYPE="Logical">No</ISCOSTCENTRESON>
<ISREVENUE TYPE="Logical">No</ISREVENUE>
<ISDEEMEDPOSITIVE TYPE="Logical">Yes</ISDEEMEDPOSITIVE>
<CANDELETE TYPE="Logical">Yes</CANDELETE>
<FORPAYROLL TYPE="Logical">No</FORPAYROLL>
<MASTERID TYPE="Number"> 2240</MASTERID>
<TNETBALANCE TYPE="Amount">0.00</TNETBALANCE>
<LANGUAGENAME.LIST>
<NAME.LIST TYPE="String">
<NAME>Dena</NAME>
</NAME.LIST>
<LANGUAGEID TYPE="Number">0</LANGUAGEID>
</LANGUAGENAME.LIST>
</LEDGER>
</TALLYMESSAGE>
</DATA>
</BODY>
</ENVELOPE>
下面是我的 php 插入连接代码
<?php
$con = mysql_connect("localhost:3306","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("temp", $con);
if(!$xml=simplexml_load_file('./xml/data.xml')){
trigger_error('Error reading XML file',E_USER_ERROR);
}
foreach ($xml as $syn)
{
$candelete = $syn->candelete;
$forpayroll = $syn->forpayroll;
$name = $syn->name;
$sql = "INSERT INTO vtiger (candelete, forpayroll, name) VALUES ('$candelete','$forpayroll','$name')";
$query = mysql_query($sql);
if (!$query)
{
echo ('Error: ' . mysql_error());
}
else
{
echo "Record added";
}
}
mysql_close($con);
?>