duankuaiwang2706 2012-06-14 13:01
浏览 147
已采纳

在MySQL中使用XML函数的示例。 PHP

Can someone please provide an example of how to store, and read xml data into MySQL? I'm using php, and I've read this documentation: http://dev.mysql.com/doc/refman/5.6/en/xml-functions.html

But I simply cannot get results that I want.

Thank you very much. (I'm using this because I have a lot of calls to the data stored in the xml, and I need faster functions.)

[EDIT] As per request:

I currently have 30k .xml files with anywhere from 25-50 elements in each file. I ask for values in various files hundreds of times a second. I'm finding there's a huge bottleneck from the I/O actions preformed here.

I think storing the data from the .xml files into a database would make accessing the values a much faster process.

I'm asking for help/advice on how to go about this.

  • 写回答

1条回答 默认 最新

  • dsu5188 2012-06-14 13:18
    关注

    Accessing the data stored in the database will be no faster than accessing them on the disk. The database speed is provided by being able to index the data, and the contents of the XML is (I assume) not indexed.

    So unless you can take key fields out of the XML it is not going to help you.

    However, in answer to your actual question (rather than whether it is a good idea), if you are using a mysqli connection and a prepared statement:

    if ($stmt = $mysqli->prepare("INSERT INTO MY_DATA_TABLE (Id, Data) VALUES(?,?)")) 
    {   
        $stmt->bind_param('ib', $id, $data);
        for($i = 0; $i < $numfiles; $i++)
        {
            $id= $row;
            $data=  readfile($id);
            $stmt->execute();
        }
     }
    

    Something like that? (Haven't tried it).

    EDIT:

    But from your answer, if you just want to read the elements from the XML files, you probably need to look at simple XML: http://php.net/manual/en/book.simplexml.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面