Пример #1
0
 static function getNextTrialTime()
 {
     $config = Config::getConfig("db");
     $mysqli = new \mysqli($config["server"], $config["username"], $config["password"], $config["name"], $config["port"]);
     if ($mysqli->connect_errno) {
         $this->throwDBExceptionOnError($mysqli->connect_error, $mysqli->connect_errno);
     }
     //Find if there is a username/password matching the input
     $next_trial_start_q = "SELECT TIME_TO_SEC(TIMEDIFF(start,now())),TIME_TO_SEC(TIMEDIFF(end,now())) FROM `gametrials` WHERE end > NOW() ORDER BY start LIMIT 1";
     if (!($stmt = $mysqli->prepare($next_trial_start_q))) {
         $this->throwDBExceptionOnError($mysqli->error, $mysqli->errno);
     }
     if (!$stmt->execute()) {
         $this->throwDBExceptionOnError($mysqli->error, $mysqli->errno);
     }
     $diff = new \stdClass();
     $diff->start = -1;
     $diff->end = -1;
     if (!$stmt->bind_result($diff->start, $diff->end)) {
         $this->throwDBExceptionOnError($mysqli->error, $mysqli->errno);
     }
     if (!$stmt->fetch()) {
         $diff->start = -1;
         $diff->end = -1;
     }
     $stmt->free_result();
     $stmt->close();
     $mysqli->close();
     /*
      * The return value contains to elements, start and end in seconds
      */
     return $diff;
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     $config = Config::getConfig("db");
     $this->mysqli = new \mysqli($config["server"], $config["username"], $config["password"], $config["name"], $config["port"]);
     if ($this->mysqli->connect_errno) {
         $this->throwDBExceptionOnError($this->mysqli->connect_error, $this->mysqli->connect_errno);
     }
 }
Пример #3
0
 function __construct(\mysqli $mysqli_con = null)
 {
     parent::__construct();
     $config = Config::getConfig("db");
     if (!$mysqli_con) {
         @($this->mysqli_con = new \mysqli($config["server"], $config["username"], $config["password"], $config["name"], $config["port"]));
         if ($this->mysqli_con->connect_errno) {
             $this->throwDBExceptionOnError($this->mysqli_con->error, $this->mysqli_con->errno);
         }
     } else {
         $this->mysqli_con = $mysqli_con;
     }
 }