I've been developing a MMORPG game lately. And are almost done, just creating the daily cron..
I've got the following code:
// Bank Interest
$res = $db->query("
SELECT uid,
id,
rm_days,
bank
FROM sys_users
LEFT JOIN sys_users_stats ON sys_users.id = sys_users_stats.uid
") or die($db->error);
while ($row = $res->fetch_object()) {
$multiply = ($row->rm_days >= 1) ? 0.04 : 0.02;
$interest = ($row->bank >= 15000000) ? ceil(15000000 * $multiply) : ceil($row->bank * $multiply);
$res = $db->query("UPDATE sys_users_stats SET bank = bank + $interest");
$rjdRPG->addEvent($row->uid, "You have gained $$interest bank interest.");
}
Everything works ok, it even does send me the event in the game:
You have gained $24 bank interest. 01 Dec 2015 09:20 PM
Only SSH/Crontab is returning an error if I run it manually, (testing purposes) It's returning:
PHP Fatal error: Call to a member function fetch_object() on a non-object in /home/RJDGaming/tm/crons/daily.php on line 22
But it is updating the bank
column to the correct amount. And sends out a notification, so all seems ok, but i'm not sure how I should solve that PHP Fatal Error as everything is working fine. $db->error
doesn't return anything, so i'm a bit lost here.
A finger pointing in the right direction would be greatly appreciated.