2013-10-04 73 views
0

值沒有被插入,也沒有顯示錯誤。任何想法,以我的插入發生了什麼?xml到mysql simplexml_load_string,沒有插入

<?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 />" 
} 
+0

什麼顯示'var_dump($ xml)'? –

回答

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 />" 
}