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

高洛峰
Release: 2023-03-03 22:40:02
Original
1236 people have browsed it

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>";
}
?>
Copy after login

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.


Related labels:
xml
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template