Example #1
0
<?php

require 'database.php';
$dbh = Database::handle();
//$dbh->exec('TRUNCATE TABLE sessions');
$dbh->exec('DELETE FROM sessions');
$dbh->exec('DELETE FROM group_requests');
$dbh->exec('DELETE FROM groups');
echo "<html><pre>Done. \nPDO::errorInfo():\n";
print_r($dbh->errorInfo());
echo '</pre>';
Example #2
0
 /**
  * Retrieves pending group request for given session.
  * If no group request is pending, returns FALSE.
  * 
  * If multiple group requests are pending (though this shouldn't happen),
  * returns the first request returned by the database
  * (in all likelihood, the oldest one).
  * 
  * @param Session $session
  * @return GroupRequest pending group request or FALSE if none is pending
  */
 public static function retrieveRequest(Session $session)
 {
     $dbh = Database::handle();
     $sth = $dbh->prepare('SELECT * FROM group_requests WHERE session = ?');
     $sth->execute(array($session->id));
     if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $expires = Util::sql2unixtime($row['expires']);
         if ($expires == 0) {
             $expires = NULL;
         }
         return new GroupRequest($session, $expires);
     } else {
         return FALSE;
     }
 }
Example #3
0
 /** Updates this group's data in the database. */
 public function saveData()
 {
     $dbh = Database::handle();
     $sth = $dbh->prepare('UPDATE groups SET data = :data WHERE id = :id');
     $sth->bindValue(':data', serialize($this->data));
     $sth->bindValue(':id', $this->id);
     $sth->execute();
 }
Example #4
0
 /**
  * Sets this session to the given status.
  *
  * @param int $status the status code for this session
  */
 public function setStatus($status)
 {
     if (!in_array($status, self::$status_codes)) {
         throw new InvalidArgumentException('invalid status code');
     } else {
         // set status
         $this->status = $status;
         // save status in db
         $dbh = Database::handle();
         $sth = $dbh->prepare('UPDATE sessions SET status = ? WHERE session_id = ?');
         $sth->execute(array($this->status, $this->id));
     }
 }
Example #5
0
 /**
  * FOR INTERNAL USE ONLY.
  */
 public static function setHandle($handle)
 {
     self::$handle = $handle;
     self::$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
Example #6
0
 /** Returns the ID of this game in the database. */
 public function getID()
 {
     $dbh = Database::handle();
     $sth = $dbh->prepare('SELECT id FROM games WHERE game = ?');
     $sth->execute(array($this->code));
     $row = $sth->fetch(PDO::FETCH_ASSOC);
     return $row['id'];
 }
Example #7
0
 /**
  * FOR INTERNAL USE ONLY.
  */
 public static function setHandle($handle)
 {
     self::$handle = $handle;
 }