最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

php读取xml文件内容,并循环写入mysql数据库

PHP 有客 113浏览
<?php
$dbconn = mysql_connect("localhost","root","root");
$db = mysql_select_db("xbrl",$dbconn);

$xml = simplexml_load_file("test.xml");
$name = "" ;
$price = 0.00 ;
foreach ($xml->children() as $child){
    $i = 0 ;
    foreach ($child->children() as $kid){
        if($i==0){
            $name = $kid ;
            $i++ ;
        }else{
            $price = $kid ;
            $i--;
        }
    }
    $sql = "insert into t_car(name,price) values('$name',$price)" ;
    mysql_query($sql,$dbconn);
}?>

转载请注明:有客帮 » php读取xml文件内容,并循环写入mysql数据库