Simple Cron SQL Job


Active member
Hi everyone, I have some code I want to enable for a cron job to update a table based on a custom field. I'm trying to convert my straight PHP script to what I think is Xenforo friendly but I could be wrong. However I seem to be having issues with the insert query, can anyone comment or even let me know if the whole thing has been done wrong? Thanks!


class twitch_cron {
protected static $queries = array(
        'deleteQuery' => 'TRUNCATE TABLE `xf_twitch_streams`',
        'userQuery' => 'SELECT * FROM xf_user_field_value WHERE field_id = "twitch" AND field_value <> ""',
        'insertQuery' => 'INSERT INTO `xf_twitch_streams` (twitch_username, twitch_viewers) VALUES ($data[0],$viewer[0])'
    public static function getUpdate()

        $db = XenForo_Application::get('db');
        foreach($db as $user) {
            $twitchuser[] = $user['field_value'];
            $data = json_decode(file_get_contents('' . $twitchuser[0]));
            $viewer[0] = $data[0]->channel_count;