Home >Backend Development >PHP Tutorial >Implementation method of php operating xml and inserting it into database

Implementation method of php operating xml and inserting it into database

高洛峰
高洛峰Original
2016-12-22 14:27:551230browse

As shown below:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
mysql_connect(&#39;localhost&#39;, &#39;root&#39;, &#39;&#39;);
mysql_select_db(&#39;test&#39;);
mysql_query(&#39;SET names utf8&#39;);
$xml_array=simplexml_load_file(&#39;suggest.xml&#39;); //将XML中的数据,读取到数组对象中
 
foreach($xml_array as $tmp){
    $sql = "insert into `countries` (`id` ,`value`) VALUES (NULL , &#39;".$tmp->field."&#39;)";
    mysql_query($sql);
echo $tmp->field."<br>";
}
?>

The above implementation method of php operating xml and inserting it into the database is all the content shared by the editor. I hope it can give you a reference, and I hope you will support PHP more. Chinese website.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn