function findEmptyKey($table, $column) { $j = false; @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; exit; } else { $db->select_db("UMBRELLA"); $query = "select " . $column . " from " . $table; $result = $db->query($query); $num_result = $result->num_rows; $d = array(); for ($i = 0; $i < $num_result; $i++) { $row = $result->fetch_assoc(); //echo "<p>".$row[$column]."</p>"; $d[$i] = $row[$column]; } //echo "<p>Number of results: ".$num_result."</p>"; sort($d); for ($z = 0; $z < $num_result; $z++) { if ($z != $d[$z]) { $j = $z; break; } } if ($j == false) { $j = count($d); } } $db->close(); return $j; }
function strategies_getStatistics($tournament) { $tournament = intval($tournament); $link = getDBConnection(); if (mysqli_select_db($link, getDBName())) { $query = "SELECT COUNT(*) as cnt, DAY(date) as dt FROM strategies " . ($tournament == -1 ? "" : " WHERE tournament=" . $tournament) . " GROUP BY DATE(date)"; return mysqli_fetch_all(mysqli_query($link, $query)); } }
function connectDB() { $conn = null; try { $conn = new PDO(getPDODrv() . ":dbname=" . getDBName() . ";host=" . getDBHost(), getDBUser(), getDBPass()); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //echo "PDO connection object created"; // We *always* enforce this $conn->exec('SET NAMES utf8mb4;'); } catch (PDOException $e) { echo $e->getMessage(); } return $conn; }
function getTournamentStrategies($tournamentId) { $tournamentId = intval($tournamentId); $link = getDBConnection(); $data = array(); if (mysqli_select_db($link, getDBName())) { $query = mysqli_query($link, "SELECT str.id AS strategy, usr.login AS login FROM strategies AS str " . " INNER JOIN users AS usr ON usr.id = str.user " . "WHERE str.tournament = {$tournamentId} AND str.status = 'ACT'"); while ($row = mysqli_fetch_assoc($query)) { $data[] = $row; } mysqli_free_result($query); } return $data; }
<?php include_once 'procedures.php'; $s1 = intval($_POST['strategyId']); $gameId = intval($_POST['gameId']); $tournamentId = intval($_POST['tournamentId']); $result = getUserStrategy($gameId, $tournamentId); $link = getDBConnection(); if (mysqli_select_db($link, getDBName())) { if (mysqli_num_rows($result) > 0) { $s2 = intval(mysqli_result($result, 0)); mysqli_query($link, "INSERT INTO duels SET round = -1, strategy1 = {$s1}, strategy2 = {$s2}, status = 'W'"); mysqli_query($link, "INSERT INTO duels SET round = -1, strategy1 = {$s2}, strategy2 = {$s1}, status = 'W'"); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { pclose(popen("start /B php -q runDuels.php", "r")); } else { exec("nohup /usr/bin/php -f ./runDuels.php > /dev/null 2>&1 &"); } } }
public function read($id) { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Compound_>read()</p>"; $db->select_db("UMBRELLA"); $result = $db->query('select compound_id from COMPOUND'); $num_results = $result->num_rows; $a = false; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); if ($id == $row['compound_id']) { //echo "<p>Exists!</p>"; $a = true; break; } } if (!is_integer(intval($id))) { $a = false; } if ($a == false) { //echo "<p>Id does not exist!<p>"; $db->close(); return false; } $query = "select * from COMPOUND where compound_id = " . $id; $result = $db->query($query); $row = $result->fetch_assoc(); $this->__set('compound_id', $row['compound_id']); $this->__set('name', $row['name']); $this->__set('value', $row['value']); $this->__set('metric', $row['metric']); //echo "<p> Query : ".$query."</p>"; $result = $db->query($query); //echo "<p>Error message: ".mysql_error()."</p>"; @$db->close(); return true; } }
public function read($id) { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Successful DB read connection</p>"; $db->select_db("UMBRELLA"); $result = $db->query('select demographic_id from DEMOGRAPHIC'); $num_results = $result->num_rows; $a = false; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); if ($id == $row['demographic_id']) { //echo "<p>Exists!</p>"; $a = true; break; } } if (!is_integer(intval($a))) { $a = false; } if ($a == false) { echo "<p>Id does not exist!<p>"; $db->close(); return false; } $query = "select * from DEMOGRAPHIC where demographic_id = " . $id; $result = $db->query($query); $row = $result->fetch_assoc(); $this->__set('demographic_id', $row['demographic_id']); $this->__set('user_id', $row['user_id']); $this->__set('ethnicity', $row['ethnicity']); $this->__set('gender', $row['gender']); $this->__set('illness', $row['illness']); $this->__set('dob', $row['dob']); //echo "<p> Query : ".$query."</p>"; $result = $db->query($query); //echo "<p>Error message: ".mysql_error()."</p>"; @$db->close(); return true; } }
function setCompounds($option) { if ($option == 'EXISTING') { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) $db->select_db("UMBRELLA"); $result = $db->query('select * from DOSAGE_DETAILS natural join COMPOUND where dosage_id = ' . $this->__get('dosage_id')); $num_results = $result->num_rows; //echo "<p>Number of compounds: ".$num_results."</p>"; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); $this->compounds[$i] = new compound(); $this->compounds[$i]->read($row['compound_id']); //echo "<p>Compound that existed was set</p>"; } $db->close(); return true; } } elseif ($option == 'NEW') { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Successful DB read connection</p>"; $db->select_db("UMBRELLA"); $result = $db->query('select * from COMPOUND where compound_id = 0'); $num_results = $result->num_rows; //echo "<p>Number of compounds: ".$num_results."</p>"; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); $this->compounds[$i] = new compound(); $this->compounds[$i]->read($row['compound_id']); } //echo "<p>New compounds set</p>"; $db->close(); return true; } } return $this->compounds; }
function getFromDB($table, $where = "1", $limit = -1) { $link = getDBConnection(); mysqli_select_db($link, getDBName()); if ($limit = -1) { $limit = ""; } else { $limit = "LIMIT {$limit}"; } $q = "SELECT * FROM `{$table}` WHERE ({$where}) {$limit}"; $data = array(); if ($query = mysqli_query($link, $q)) { while ($row = mysqli_fetch_assoc($query)) { $data[] = $row; } mysqli_free_result($query); } mysqli_close($link); return $data; }
function setDosages($option) { if ($option == 'EXISTING') { @($db = new mysqli('localhost', getDBUserName(0), getDBPassword(0), getDBName(0))); if (mysqli_connect_errno()) { //echo "<p>Errorrrss</p>"; @$db->close(); return false; } else { //(address_id, privilege, login, password, firstname, lastname, created) //echo "<p>Successful Getting Dosages DB read connection</p>"; $db->select_db("UMBRELLA"); //echo "<p>Successful Getting Dosages DB DB select</p>"; //where product_id = '.$this->__get('product_id') $result = $db->query("select * from DOSAGE where product_id = " . $this->__get('product_id')); //echo "<p>Successful Getting Dosages DB Query</p>"; $num_results = $result->num_rows; //echo "<p>Number results from dosages query: ".$num_results."</p>"; for ($i = 0; $i < $num_results; $i++) { //echo "<p>Fetching a dosage : ".$i."</p>"; $row = $result->fetch_assoc(); //echo "<p>fetch_assoc... row id : ".$row['dosage_id']."</p>"; $this->dosages[$i] = new dosage(); //echo "<p>Error message: ".mysql_error()."</p>"; $this->dosages[$i]->read($row['dosage_id']); //echo "<p>The dosage is called : ".$this->dosages[$i]->__get('form')."</p>"; } $db->close(); return true; //$db->close(); } } elseif ($option == 'NEW') { $this->dosages[0] = new dosage(); //FUTURE NOTE, SPECIFY A READ OPTION $this->dosages[0]->_default($this->__get('product_id')); /*$this->dosages[0]->__set('dosage_id', findEmptyKey('DOSAGE', 'dosage_id')); $this->dosages[0]->__set('product_id', $this->__get('product_id')); $this->dosages[0]->setCompounds('NEW'); */ return true; } else { return false; } //FUTURE, CREATE ADDITIONAL METHOD THAT ALLOWS THE DEVELOPER TO MANUALLY SET DOSAGES }
function getPreviousRound($roundId) { $link = getDBConnection(); $previousRound = -1; if (mysqli_select_db($link, getDBName())) { $roundId = intval($roundId); $query = mysqli_query($link, "SELECT previousRound FROM rounds WHERE id = {$roundId}"); $data = mysqli_fetch_assoc($query); $previousRound = $data['previousRound']; mysqli_free_result($query); } return $previousRound; }
function getUsersWithStrategies($tournament) { $tournament = intval($tournament); $link = getDBConnection(); mysqli_select_db($link, getDBName()); $q = "SELECT users.id as id, users.login as login FROM users " . " INNER JOIN strategies ON users.id = strategies.user " . " WHERE `group` != 'banned' AND strategies.tournament = {$tournament}" . " GROUP BY id ORDER BY login"; $data = array(); if ($query = mysqli_query($link, $q)) { while ($row = mysqli_fetch_assoc($query)) { $data[] = $row; } mysqli_free_result($query); } return $data; }