public static function register($user, $pass, $email) { $query = "insert into account(username,password,email) values('{$user}','{$pass}','{$email}')"; Mdb::nonSelectQuery($query); $query = "insert into profile(status) values('active')"; Mdb::nonSelectQuery($query); }
public static function isUserInChat($chatId, $userId) { $db = Mdb::GetConnection(); $collection = $db->selectCollection(Mdb::$dbname, 'chat'); $result = $collection->findOne(['_id' => intval($chatId), 'members' => ['$all' => [intval($userId)]]], ['_id' => true]); return empty($result) ? false : true; }
public static function getExpressions($crit) { if ($crit != "") { $query = "select * from expression\n where (lower(name) like lower('%{$crit}%')) or\n (lower(description) like lower('%{$crit}%')) or\n (lower(content) like lower('%{$crit}%')) or\n (lower(formula) like lower('%{$crit}%'))\n order by popularity desc, ts desc limit 70"; } else { $query = "select * from expression order by ts desc limit 70"; } //echo $query; return Mdb::sqlTableQuery($query); }
public function start() { $host = Config::get('mongo.host', '127.0.0.1'); $port = Config::get('mongo.port', 27017); $protocol = Config::get('mongo.protocol', 'mongodb'); $auth = Config::get('mongo.auth', true); if ($auth) { $user = Config::get('mongo.username', SITE_NAME . '_master'); $password = Config::get('mongo.password'); $dsn = $protocol . '://' . $user . ':' . $password . '@' . $host . ':' . $port; } else { $dsn = $protocol . '://' . $host . ':' . $port; } return Mdb::connection($dsn, ['connect' => true]); }
public static function nonSelectQuery($query) { try { $host = self::HOST; $baza = self::BAZA; $user = self::USER; $pass = self::PASS; self::$dsn = "mysql:host={$host};dbname={$baza}"; self::$dbh = new PDO(self::$dsn, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $pdo_izraz = self::$dbh->prepare($query); $pdo_izraz->execute(); } catch (PDOException $exc) { echo $exc->getMessage(); } self::$dbh = null; }
<?php require_once '../init.php'; $minute = (int) date('i'); $hour = (int) date('H'); if ($hour != 4) { exit; } if ($minute != 0) { exit; } $mdb = new Mdb(); $types = ['characterID', 'corporationID', 'allianceID', 'factionID', 'groupID', 'shipTypeID', 'solarSystemID', 'regionID']; $timer = new Timer(); $ninetyDayKillID = MongoFilter::getKillIDFromTime(time() - 90 * 86400); $date = new MongoDate(strtotime(date('Y-m-d'))); // Clear out ranks more than two weeks old $mdb->remove('ranksProgress', ['date' => ['$lt' => $mdb->now(-86400 * 14)]]); foreach ($types as $type) { Util::out("Started recent calcs for {$type}"); $calcStats = $mdb->find('information', ['type' => $type]); foreach ($calcStats as $row) { calcStats($row, $ninetyDayKillID); } Util::out("Completed recent calcs for {$type}"); } function calcStats($row, $ninetyDayKillID) { global $mdb, $debug; $type = $row['type']; $id = $row['id'];
public static function delete($id) { $query = "delete from expression where id={$id}"; Mdb::nonSelectQuery($query); }
<?php require_once '../init.php'; $minute = (int) date('i'); if ($minute != 0) { exit; } $mdb = new Mdb(); $killsLastHour = new RedisTtlCounter('killsLastHour', 3600); $kills = $killsLastHour->count(); $count = $mdb->findField('storage', 'contents', ['locker' => 'totalKills']); if ($kills > 0) { Log::irc('|g|' . number_format($kills, 0) . '|n| kills processed.'); Util::out(number_format($kills, 0) . ' kills added, now at ' . number_format($count, 0) . ' kills.'); } $redis->set('zkb:totalKills', $mdb->count('killmails')); $redis->set('zkb:crestRemaining', Db::queryField('select count(*) count from kills_by_dttm where status = 0', 'count'));
public static function GetConnection() { self::$dbname = 'social-network'; $db = new MongoClient('mongodb://*****:*****@ds047335.mongolab.com:47335/social-network'); return $db; }
public static function getContent($id) { $query = "select content from expression where id={$id}"; $res = Mdb::sqlRowQuery($query); return $res['content']; }
<?php require_once '../init.php'; $mdb = new Mdb(); $old = $mdb->now(3600 * 3); // 8 hours $timer = new Timer(); $queueAllis = new RedisTimeQueue('tqAlliances', 9600); $i = date('i'); if ($i == 45) { $allis = $mdb->find('information', ['type' => 'allianceID']); foreach ($allis as $alli) { $queueAllis->add($alli['id']); } } while ($timer->stop() <= 55000) { sleep(1); $id = (int) $queueAllis->next(false); if ($id == null) { exit; } $alliance = $mdb->findDoc('information', ['type' => 'allianceID', 'id' => $id]); $id = $alliance['id']; $name = $alliance['name']; $currentInfo = $mdb->findDoc('information', ['type' => 'alliance', 'id' => $id]); $alliCrest = CrestTools::getJSON("https://public-crest.eveonline.com/alliances/{$id}/"); if ($alliCrest == null || !isset($alliCrest['name'])) { $mdb->set('information', ['type' => 'alliance', 'id' => $id], ['lastApiUpdate' => $mdb->now()]); continue; } $update = [];
public static function getForType($type) { $query = "select * from bexpression where type='{$type}'"; return Mdb::sqlTableQuery($query); }
public static function getAccForId($accid) { $query = "select * from account where id={$accid}"; return Mdb::sqlRowQuery($query); }
<?php require_once '../init.php'; $mdb = new Mdb(); $old = $mdb->now(3600 * 3); // 8 hours $timer = new Timer(); $mdb->getCollection('information')->update(['type' => 'allianceID', 'lastApiUpdate' => null], ['$set' => ['lastApiUpdate' => new MongoDate(2)]], ['multiple' => true]); $alliances = $mdb->find('information', ['type' => 'allianceID', 'lastApiUpdate' => ['$lt' => $old]], ['lastApiUpdate' => 1], 100); foreach ($alliances as $alliance) { if (Util::exitNow() || $timer->stop() > 110000) { exit; } $id = $alliance['id']; $name = $alliance['name']; //echo "$id $name\n"; $currentInfo = $mdb->findDoc('information', ['type' => 'alliance', 'id' => $id]); if (false && @$currentInfo['deleted'] == true) { $mdb->set('information', ['type' => 'alliance', 'id' => $id], ['lastApiUpdate' => $mdb->now()]); continue; } $alliCrest = CrestTools::getJSON("https://public-crest.eveonline.com/alliances/{$id}/"); if ($alliCrest == null || !isset($alliCrest['name'])) { sleep(1); $mdb->set('information', ['type' => 'alliance', 'id' => $id], ['lastApiUpdate' => $mdb->now()]); continue; } $update = []; $update['lastApiUpdate'] = $mdb->now(); $update['corpCount'] = (int) $alliCrest['corporationsCount']; $update['executorCorpID'] = (int) $alliCrest['executorCorporation']['id'];
<?php require_once '../init.php'; $minute = (int) date('i'); if ($minute != 0) { exit; } $mdb = new Mdb(); $killsLastHour = new RedisTtlCounter('killsLastHour', 3600); $kills = $killsLastHour->count(); $count = $mdb->count("killmails"); if ($kills > 0) { Log::irc('|g|' . number_format($kills, 0) . '|n| kills processed.'); Util::out(number_format($kills, 0) . ' kills added, now at ' . number_format($count, 0) . ' kills.'); } $redis->set('zkb:totalKills', $count);
public static function setLanguage($lng) { $db = Mdb::GetConnection(); $collection = $db->selectCollection(Mdb::$dbname, 'user'); $result = $collection->update(['_id' => self::getUserId()], ['$set' => ['lng' => $lng]]); }
<?php require_once '../init.php'; $minute = (int) date('i'); if ($minute != 0) { exit; } $mdb = new Mdb(); $killsLastHour = new RedisTtlCounter('killsLastHour', 3600); $kills = $killsLastHour->count(); $count = $mdb->findField('storage', 'contents', ['locker' => 'totalKills']); if ($kills > 0) { Log::irc('|g|' . number_format($kills, 0) . '|n| kills processed.'); Util::out(number_format($kills, 0) . ' kills added, now at ' . number_format($count, 0) . ' kills.'); }
public static function updateExpression($id, $name, $desc, $content) { $query = "update expression set name='{$name}',description='{$desc}',content='{$content}' where id={$id}"; Mdb::nonSelectQuery($query); }