0

没有插入值,也没有显示错误。关于我的插入发生了什么的任何想法?

<?php
$string = <<<XML
<?xml version='1.0'?> 
<setnames>
<country>
<countryCode>AD</countryCode>
<countryName>Andorra</countryName>
</country>
<country>
<countryCode>AE</countryCode>
<countryName>United Arab Emirates</countryName>
<isoNumeric>784</isoNumeric>
</country>
<country>
<countryCode>AF</countryCode>
<countryName>Afghanistan</countryName>
<isoNumeric>784</isoNumeric>
</country>
</setnames>
XML;

$xml = simplexml_load_string($string);

foreach ($xml as $country) 
{

mysqli INSERT INTO setnames 
VALUES ($country->countryCode, $country->countryName, $country->isoNumeric);

    echo $country->countryCode . "<br />";
    echo $country->countryName . "<br />";
    echo $country->isoNumeric . "<br />"
}
4

1 回答 1

1

$xml 变量是一个对象,也不是一个数组。所以,你应该像这样做你的 foreach :

foreach ($xml->country as $country) 
{

mysqli INSERT INTO setnames 
VALUES ($country->countryCode, $country->countryName, $country->isoNumeric);

    echo $country->countryCode . "<br />";
    echo $country->countryName . "<br />";
    echo $country->isoNumeric . "<br />"
}
于 2013-10-04T20:28:21.347 回答