douren1928 2014-08-22 13:51
浏览 37
已采纳

将xml数据导入mysql数据库

i need to import this xml data into mysql database.. i dont have clear idea about it.

this is my .xml file

<employee>
        <row>
            <field name="employee_name">Syed</field>
            <field name="employee_code">101</field>
            <field name="employee_email">syed@gmail.com</field>
            <field name="employee_designation">Trainee</field>
            <field name="employee_number">7412347798</field>
            <field name="employee_salary">6000</field>
            <field name="employee_age">21</field>
        </row>
        <row>
            <field name="employee_name">Hari</field>
            <field name="employee_code">102</field>
            <field name="employee_email">hari@gmail.com</field>
            <field name="employee_designation">Trainee</field>
            <field name="employee_number">9895852525</field>
            <field name="employee_salary">6000</field>
            <field name="employee_age">23</field>
        </row>
        <row>
            <field name="employee_name">Raja</field>
            <field name="employee_code">103</field>
            <field name="employee_email">raja@gmail.com</field>
            <field name="employee_designation">Trainee</field>
            <field name="employee_number">9956853458</field>
            <field name="employee_salary">6000</field>
            <field name="employee_age">23</field>
        </row>
        <row>
            <field name="employee_name">imran</field>
            <field name="employee_code">104</field>
            <field name="employee_email">imran@gmail.com</field>
            <field name="employee_designation">Trainee</field>
            <field name="employee_number">9836052525</field>
            <field name="employee_salary">6000</field>
            <field name="employee_age">21</field>
        </row>
        <row>
            <field name="employee_name">Sam</field>
            <field name="employee_code">105</field>
            <field name="employee_email">sam@gmail.com</field>
            <field name="employee_designation">Trainee</field>
            <field name="employee_number">8625852525</field>
            <field name="employee_salary">6000</field>
            <field name="employee_age">21</field>
        </row>
        <row>
            <field name="employee_name">vinod</field>
            <field name="employee_code">106</field>
            <field name="employee_email">vinod@gmail.com</field>
            <field name="employee_designation">Trainee</field>
            <field name="employee_number">7225852525</field>
            <field name="employee_salary">6000</field>
            <field name="employee_age">24</field>
        </row>
    </employee>

my routine for this function is,

 if ($file) {
                $handle = simplexml_load_file($file);                           //  Open the file and read
                while($strBookData = fgets($handle, 4096)) {        //  To get Array 
                    $strDatas[] = $strBookData;
                    $strTableColumn = count($strBookData);              // To Get Column count
                }

i dont know what to do further.. can any one give me suggestions?? thanks in advance :)

  • 写回答

1条回答 默认 最新

  • douzhan4522 2014-08-22 14:26
    关注

    You simply have to get all rows as an array. Just do it in a loop. And then update the table. Like so:

    while($row = $this->nextRow()) {
        mysql_query("INSERT INTO table (name, code) VALUES ($row['name']), $row['code']");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?