我想从xml插入数据,我有300多个行,但是我的查询仅插入59-60行。请帮助我解决问题。
在下面的XML中,我删除了所有详细信息,仅描述了示例布局。
实际的XML布局文件如下所示
<Listings>
<Listing>
<Ad_Type>Rent</Ad_Type>
<Unit_Type>Apartment</Unit_Type>
<Unit_Builtup_Area>938.00</Unit_Builtup_Area>
<No_of_Bathroom>2</No_of_Bathroom>
<Price>75000</Price>
<Frequency>per year</Frequency>
</Listing>
<Listing>
......
</Listing>
<Listing>
......
</Listing>
<Listing>
......
</Listing>
<Listing>
......
</Listing>
</Listings>
我的PHP查询
<?php
$conn = mysqli_connect("localhost", "root", "root", "xxxx");
$affectedRow = 0;
echo 'Current PHP version: ' . phpversion();
//$xml = simplexml_load_file("my xml file url here") or die("Error: Cannot create object");
foreach ($xml->children() as $row) {
$price = $row->Price;
$Bathroom = $row->No_of_Bathroom;
$Ad_Type = $row->Ad_Type;
$Unit_Type = $row->Unit_Type;
$Unit_Builtup_Area = $row->Unit_Builtup_Area;
$ref = $row->Property_Ref_No;
$frequency = $row->Frequency
$sql = "INSERT INTO properties(price, Bathroom, Ad_Type, Unit_Type, Unit_Builtup_Area, ref_no, frequency) VALUES (
'" . $price. "',
'" . $Bathroom. "',
'" . $Ad_Type. "',
'" . $Unit_Type. "',
'" . $Unit_Builtup_Area. "',
'" . $frequency. "',
'" . $ref. "'
)";
$result = mysqli_query($conn, $sql);
if (! empty($result)) {
$affectedRow ++;
echo 'Rows created '.$affectedRow.'<br>';
} else {
$error_message = mysqli_error($conn) . "\n";
}
}
?>
<h2>Insert XML Data to MySql Table Output</h2>
<?php echo $affectedRow ?>
<?php
if ($affectedRow > 0) {
$message = $affectedRow . " records inserted";
} else {
$message = "No records inserted";
}
?>
我在xml中有300多个列表,但是查询仅插入60行。我期望查询插入XML中的所有行。