admin管理员组文章数量:1130349
I have a website that auto generates odds data to mysql table via cron job every 2hrs. Over time the data in my table is exceeding the limit set from my hosting of 100mb.
I want to stop my table from overloading and to do this, I want it to delete previous odds data and only show the latest odds. The odds data is in the wp_postmeta table.
Here is a sample of data in one row:
- meta_id 3141189
- post_id 20583
- meta_key
Odd - meta_value
{"FixtureMatch_Id":"392665","Bookmaker":"18BET","UpdatedDate":"2018-12-14T20:57:46.98","Type":"Asian Handicap","HomeOdds":"1.49","AwayOdds":"2.71","Handicap":"2"}
So I have lots of these rows, and I want to know how I can use PHP to remove old odds, lets say odds that are before 5 days are deleted, how would I do this?
I have tried to do this, but heard it doesn't work like that.
global $wpdb; // Global object database variable
$updatedDate = [];
//set how many days odds will show until.. currently set to -5 days.
$endDatefind = (new \DateTime('now'))->modify("-5 day")->format('Y-m-d'); // creating datetime object
//finds all dates from 2000 to 5 days before todays date
$findquery = $wpdb->get_results ( "
SELECT *
FROM `wp_postmeta`
WHERE`meta_key` = 'Odd'
AND STR_TO_DATE(meta_value, '%Y-%m-%d') >= '2000-01-01'
AND STR_TO_DATE(meta_value, '%Y-%m-%d') =< '$endDatefind'
");
Anyone know how I can do it?
I have a website that auto generates odds data to mysql table via cron job every 2hrs. Over time the data in my table is exceeding the limit set from my hosting of 100mb.
I want to stop my table from overloading and to do this, I want it to delete previous odds data and only show the latest odds. The odds data is in the wp_postmeta table.
Here is a sample of data in one row:
- meta_id 3141189
- post_id 20583
- meta_key
Odd - meta_value
{"FixtureMatch_Id":"392665","Bookmaker":"18BET","UpdatedDate":"2018-12-14T20:57:46.98","Type":"Asian Handicap","HomeOdds":"1.49","AwayOdds":"2.71","Handicap":"2"}
So I have lots of these rows, and I want to know how I can use PHP to remove old odds, lets say odds that are before 5 days are deleted, how would I do this?
I have tried to do this, but heard it doesn't work like that.
global $wpdb; // Global object database variable
$updatedDate = [];
//set how many days odds will show until.. currently set to -5 days.
$endDatefind = (new \DateTime('now'))->modify("-5 day")->format('Y-m-d'); // creating datetime object
//finds all dates from 2000 to 5 days before todays date
$findquery = $wpdb->get_results ( "
SELECT *
FROM `wp_postmeta`
WHERE`meta_key` = 'Odd'
AND STR_TO_DATE(meta_value, '%Y-%m-%d') >= '2000-01-01'
AND STR_TO_DATE(meta_value, '%Y-%m-%d') =< '$endDatefind'
");
Anyone know how I can do it?
本文标签: mysqlKeeping database within limitsplease help
版权声明:本文标题:mysql - Keeping database within limits, please help! 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749097455a2315481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论