Hi everyone, I have a custom table in the database and I'm trying to run a few queries and update the new table. This seems to run fine but I get zero entries into the database. Is there a new or preferred method of inserting into the database?
PHP:
<?php
namespace GuildAdmin;
class HostedStream {
public static function getHtml()
{
//Find donator members
$finderuser = \XF::finder('XF:User');
$users = $finderuser->pluckFrom('user_id')->where('secondary_group_ids', '=', '13')->fetch();
foreach($users as $don){
//Grab all users with twitch usernames in profile
$finder = \XF::finder('XF:UserFieldValue');
$username = $finder->pluckFrom('field_value')->where('user_id', '=', $don)->fetchOne();
//Cycle through each user with Twitch username in profile and check if they are online or offline.
if ($username !== null) {
$TwitchClientid = 'r20';
$url = 'https://api.twitch.tv/helix/streams?user_login='. $username;
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array(
'Client-ID: ' . $TwitchClientid . '',
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url
));
$response = curl_exec($ch);
curl_close($ch);
if ($response == null) {
//stream is offline = 2
$db = $this->db();
$db->insert('xf_twitch', [
'tw_username' => $TU,
'on_off' => '2'
]);
} else {
//Stream is online = 1
$db = $this->db();
$db->insert('xf_twitch', [
'tw_username' => $TU,
'on_off' => '1'
]);
}
}
}
}
}
?>