简体   繁体   English

在mysql在线数据库中更新数据的最佳方式

[英]Best way to update data in mysql online database

I have an online sql database with a few tables for users matches and bets .我有一个在线 sql 数据库,其中包含一些用于users matchesbets表。 When I update the result of any game, I need the status of all bets containing that game in the bet table to be updated.当我更新任何游戏的结果时,我需要更新投注表中包含该游戏的所有投注的状态。 So for example if I update game 8 with the result home win I need all bets which have game 8 in them to be updated as either lost , won or still open .因此,例如,如果我以home win的结果更新第8场比赛,我需要将所有包含第8场比赛的投注更新为lostwon或仍处于open

The way I do this currently is that when the user turns on my android app, I retrieve all the information about the games and all the information about the user's bets using asynctasks.我目前这样做的方式是,当用户打开我的 android 应用程序时,我使用 asynctasks 检索有关游戏的所有信息以及有关用户下注的所有信息。 I then do some string comparisons in my app and then I update the data in my database using another asynctask.然后我在我的应用程序中进行一些字符串比较,然后我使用另一个异步任务更新我的数据库中的数据。 The issue is that this wastes a lot of computation time and makes my app UI laggy.问题是这浪费了大量计算时间并使我的应用程序 UI 滞后。

As someone with minimal experience with php and online databases, I'd like to ask is there a way to carry out these things in the database itself either periodically (every 3 hours for example) or whenever the data in the games table is changed using a php file for example which is automatically run?作为对 php 和在线数据库经验最少的人,我想问一下有没有办法在数据库本身中定期(例如每 3 小时一次)或每当games表中的数据更改时执行这些操作例如一个自动运行的php文件?

I tried looking for some kind of onDataChanged function but couldn't find anything.我试图寻找某种onDataChanged函数,但找不到任何东西。 I'm also not sure how to make a php file run and update data without getting the app involved.我也不确定如何在不涉及应用程序的情况下运行 php 文件并更新数据。

Another idea I had was to create a very simple app which I wouldn't distribute to anyone but just keep on my phone with an update button which I could press and trigger a php file to carry out these operations for all users in my database.我的另一个想法是创建一个非常简单的应用程序,我不会将其分发给任何人,而只是在我的手机上保留一个更新按钮,我可以按下并触发一个 php 文件来为我数据库中的所有用户执行这些操作。

I would appreciate some advice on this from someone who has experience.我希望有经验的人就此提出一些建议。

Thanks :).谢谢 :)。

You can easily execute php script periodically if your hosting provider supports script executors like Cron.如果您的托管服务提供商支持像 Cron 这样的脚本执行器,您可以轻松地定期执行 php 脚本。

About updating game status multiple times, first check tables engine.关于多次更新游戏状态,首先检查表引擎。 If you are using engine like InnoDB you can create relationship between those tables, so updating status of one row will affect all connected to them.如果您使用像 InnoDB 这样的引擎,您可以在这些表之间创建关系,因此更新一行的状态将影响所有连接到它们的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM