public static function leagueExists($leagueid) { $leagueid = (int) $leagueid; $db = Db::obtain(); $r = $db->queryFirstPDO('SELECT leagueid FROM ' . Db::realTablename('leagues') . ' WHERE leagueid = ?', array($leagueid)); return (bool) $r; }
/** * @param Item[] $data list of items */ public function save(array $data) { $db = Db::obtain(); $dataToInsert = array(); foreach ($data as $item) { array_push($dataToInsert, $item->getDataArray()); } $db->insertManyPDO(Db::realTablename('items'), array('id', 'name', 'cost', 'secret_shop', 'side_shop', 'recipe', 'localized_name'), $dataToInsert, true); }
/** * @param string $id * @return bool */ public static function playerExists($id = null) { if (null === $id) { return false; } $db = Db::obtain(); $result = $db->queryFirstPDO('SELECT steamid FROM ' . Db::realTablename('users') . ' WHERE steamid = ?', array($id)); return $result['steamid'] === (string) $id; }
public static function tearDownBeforeClass() { $db = Db::obtain(); $db->exec('DELETE FROM picks_bans'); $db->exec('DELETE FROM ability_upgrades'); $db->exec('DELETE FROM additional_units'); $db->exec('DELETE FROM slots'); $db->exec('DELETE FROM matches'); $db->exec('DELETE FROM leagues'); }
public function testUpdate() { $this->player->set('personaname', 'test'); $mapperDb = new PlayerMapperDb(); $mapperDb->save($this->player); $db = Db::obtain(); $r = $db->fetchArrayPDO('SELECT * FROM users'); $player = array_pop($r); $this->assertEquals('test', $player['personaname']); }
public function save() { $leagueid = $this->getLeagueId(); $prizePool = $this->getPrizePool(); if (null === $prizePool || null === $leagueid) { return; } $db = Db::obtain(); $data = array('league_id' => $leagueid, 'prize_pool' => $prizePool); $db->insertPDO(Db::realTablename('league_prize_pools'), $data); echo $db->getError(); }
public function load() { $db = Db::obtain(); $players = array(); $ids = $this->getIdsString(); if (count($this->_ids) === 0) { return array(); } $result = $db->fetchArrayPDO('SELECT * FROM ' . Db::realTablename('users') . ' WHERE steamid IN (' . $ids . ')', array()); foreach ($result as $r) { $player = new Player(); $player->setArray((array) $r); $players[$player->get('steamid')] = $player; } return $players; }
/** * Get matches ids with provided heroid or account_id (query for "slots" table) * @return array */ private function _getMatchesIdsFromSlots() { $db = Db::obtain(); $forSlots = 'SELECT match_id ' . Db::realTablename('FROM slots') . ''; $whereForSlots = ''; $dataForSlots = array(); if (null !== $this->getHeroId()) { $whereForSlots .= 'heroid = ? AND '; array_push($dataForSlots, $this->getHeroId()); } if (null !== $this->getAccountId()) { $whereForSlots .= 'account_id = ? AND '; array_push($dataForSlots, $this->getAccountId()); } if (trim($whereForSlots) !== '') { $forSlots .= ' WHERE ' . substr($whereForSlots, 0, strlen($whereForSlots) - 4); } $matchesIds = $db->fetchArrayPDO($forSlots, $dataForSlots); $ret = array(); foreach ($matchesIds as $val) { array_push($ret, $val['match_id']); } return $ret; }
/** * Delete match data from db * * @param int $matchId * @return bool */ public static function matchExists($matchId) { $matchId = (int) $matchId; $db = Db::obtain(); $r = $db->queryFirstPDO('SELECT match_id FROM ' . Db::realTablename('matches') . ' WHERE match_id = ?', array($matchId)); return (bool) $r; }
public function testDelete() { $additionalMatchId = 886357301; $matchMapperWeb = new MatchMapperWeb($additionalMatchId); $match = $matchMapperWeb->load(); $matchMapperDb = new MatchMapperDb(); $matchMapperDb->save($match); $matchesMapperDb = new MatchesMapperDb(); $matchesMapperDb->delete(array($additionalMatchId, $this->matchId)); $db = Db::obtain(); $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM matches'))); $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM slots'))); $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM additional_units'))); $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM ability_upgrades'))); $this->assertEquals(0, count($db->fetchArrayPDO('SELECT * FROM picks_bans'))); }
<?php require_once 'vendor/autoload.php'; require_once 'api-key.php'; use Dota2Api\Api; use Dota2Api\Utils\Db; Api::init(API_KEY, array('localhost', 'root', '', 'dota2_dev_db', ''), false); $db_name = 'dota2_api_test_db'; $db = Db::obtain(); $db->exec('CREATE DATABASE ' . $db_name); Db::clean(); $db = Db::obtain('localhost', 'root', '', 'dota2_api_test_db', ''); $db->connectPDO(); $db->exec(file_get_contents('db_latest.sql')); register_shutdown_function(function () { $db = Db::obtain(); $db->exec('DROP DATABASE dota2_api_test_db'); });
protected function tearDown() { Db::obtain()->exec('DELETE FROM league_prize_pools'); Db::obtain()->exec('DELETE FROM leagues'); }
public static function tearDownAfterClass() { Db::obtain()->exec('DELETE FROM league_prize_pools'); Db::obtain()->exec('DELETE FROM leagues'); }