getMessage()); } foreach ($monthly_totals as $monthly) { // Format date to timestamp. $timestamp = $monthly['yymm'] . '-01 01:01:01-01'; try { $p = R::findOrCreate('monthlystats', ['date_checked' => $timestamp]); $p['total_users'] = $monthly['users']; $p['total_posts'] = $monthly['posts']; $p['total_comments'] = $monthly['comments']; $p['total_pods'] = $monthly['pods']; if ($monthly['downtime']) { $p['total_uptime'] = round($monthly['downtime'] / $monthly['uptime'] * 100); } else { $p['total_uptime'] = 100; } R::store($p); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); } }