使用外部 XML 更新/填充 mysql 数据库的有效方法 [英] Efficient way to update/populate a mysql database with external XML

查看:23
本文介绍了使用外部 XML 更新/填充 mysql 数据库的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用游戏 API 的小应用程序,不幸的是,该 API 并不是世界上最快的.它也只输出大型 XML 文件.

I am working on a small app that utilizes a game API, unfortunately the API is not the fastest in the universe. It also only outputs large XML files.

我想获取其中一个文件并将其直接放入数据库中,这样每次用户需要更新某些内容时就不会从他们的服务器中查询它.相反,它查询我的本地数据库.我会每隔几个小时通过一次 cron 工作来获取它,因此它不应该影响性能.

I want to grab one of these files and place it directly into a database, this way it is not being queried from their servers each time a user needs to update something. Instead its querying my local database. I would grab it via a cron job every few hours, thus it shouldn't affect performance.

我的问题是:对我来说,从他们的服务器获取 XML 文件并使用他们的更新版本更新我的数据库的最有效方法是什么?[请注意,为此我只使用 PHP,并希望保持这种状态.

My question is: What is the most efficient way for me to grab the XML file from their server and update my database with their updated version? [As a note, I am using only PHP for this and want to keep it that way.

感谢您的帮助!

推荐答案

我会使用类似 simpleXML.

我猜 XML 文件的元素与其他值基本相同?在这种情况下,您需要创建一个 PreparedStatement 并绑定新的每个条目的参数.这是执行此操作的最高效方法.

I guess the XML-files have elements which are basically the same with other values? In this case, you'll want to create a PreparedStatement and bind new parameters for every entry. This is the most performant way to do this.

但如果您最关心性能,PHP 不是您的选择.您可以使用 Java(例如)来解析 XML 文件并在您的数据库中写入条目.使用哪种语言访问填充的数据库无关紧要.

But if you care mostly about performance, PHP isn't the way to go. You could use Java (for example) to parse the XML-File and write the entry's in your Database. With which language you access the filled database is of no concern.

这篇关于使用外部 XML 更新/填充 mysql 数据库的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆