how insert data from xml to mysql with loops
enter code here`hi how can help me开发者_运维问答 ? i have Problem in my script
i want save this xml file in the mysql db
the xml file
<?xml version="1.0" encoding="utf-8"?>
<STYLE>
<settings><style_name>default</style_name>
<style_version>1.0</style_version>
</settings>
<tpl>
<tpl_name>body</tpl_name>
<tpl_display_area>body</tpl_display_area>
<tpl_des>body</tpl_des>
<tpl_source><![CDATA[<
Body src
]]></tpl_source>
<tpl_name>footer</tpl_name><tpl_display_area>footer</tpl_display_area><tpl_des>footer</tpl_des>
<tpl_source>
<![CDATA[>
source Footer
]]>
</tpl_source>
<tpl_name>closing</tpl_name><tpl_display_area>close</tpl_display_area><tpl_des>closing</tpl_des><tpl_source><![CDATA[<center><h3>Our website close right now </h3></center>]]></tpl_source>
<tpl_name>display</tpl_name>
<tpl_display_area>display</tpl_display_area>
<tpl_des>display</tpl_des>
<tpl_source>
<![CDATA[{include file='db:header'}
{include file='db:body'}
{include file='db:footer'}]]>
</tpl_source>
<tpl_name>right block</tpl_name>
<tpl_display_area>right_block</tpl_display_area>
<tpl_des>right block</tpl_des>
<tpl_source><![CDATA[ right src ]]></tpl_source>
<tpl_name>left block</tpl_name>
<tpl_display_area>left_block</tpl_display_area>
<tpl_des>left block</tpl_des>
<tpl_source>
<![CDATA[<div class="left">
</div>]]>
</tpl_source>
<tpl_name>header</tpl_name>
<tpl_display_area>header</tpl_display_area>
<tpl_des>header</tpl_des><tpl_source><![CDATA[<head></head>]]></tpl_source>
</tpl>
</STYLE>
There was 7 templates i want to save settings tags in the style information table one time only the table style_name varchar(255) version varchar(255)
and want save all 7 template in mysql table
table Map
tpl_name varchar(255) tpl_display_area varchar(255) tpl_des varchar(255) tpl_source text
please help me
You could use the SimpleXML-class to parse the XML file and then use the MySQLi-class to write the values in the Database.
Examples and Tutorials on both this things can be found in the PHP-Manual, the Comments in the PHP-Manual and on Google.
Step by Step:
- Parse your XML-File and get the Values from it (save them in an Array)
- Connect to your MySQL Database
- Create a PreparedStatement for the Insert
- Loop over your Array and Insert the Values in the Database
- Close the Database connection
精彩评论