Changeset 20


Ignore:
Timestamp:
Apr 9, 2007, 2:36:25 PM (12 years ago)
Author:
julian
Message:
  • Added module Globals, which is to do project specific stuff
  • Fixed bug in session writing
Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/Core.class.php

    r5 r20  
    4848        }
    4949
     50        /**
     51         * Initialize global stuff
     52         */
     53        Factory::singleton('Globals');
    5054
    5155        /**
  • trunk/modules/DB.class.php

    r10 r20  
    33class DB extends ModuleTemplate {
    44    protected $queriesCounter = 0;
    5     protected $dBObject = NULL;
     5    protected $dbObject = NULL;
    66    protected $curResult = NULL;
    77    protected $queryTime = 0;
     8    protected $destructFunctions = array();
    89
    910    public function initializeMe() {
    10         $this->dBObject = new mysqli;
     11        $this->dbObject = new mysqli;
    1112
    12         @$this->dBObject->connect($this->getC('dbServer'),$this->getC('dbUser'),$this->getC('dbPassword'),$this->getC('dbName'));
     13        @$this->dbObject->connect($this->getC('dbServer'),$this->getC('dbUser'),$this->getC('dbPassword'),$this->getC('dbName'));
    1314        if(mysqli_connect_error() != '') die('Database error: <b>'.mysqli_connect_error().'</b>');
    1415
     
    4041
    4142    public function query($query) {
    42         $starTime = Functions::getMicroTime();
    43         if(($this->curResult = $this->dBObject->query($query)) == FALSE) die('Database error: <b>'.$this->dBObject->error.'</b><br/>Query: <b>'.$query.'</b>');
    44         $this->queryTime += Functions::getMicroTime()-$starTime;
     43        $startTime = Functions::getMicroTime();
     44        if(!($this->curResult = $this->dbObject->query($query))) die('Database error: <b>'.$this->dbObject->error.'</b><br/>Query: <b>'.$query.'</b>');
     45        $this->queryTime += Functions::getMicroTime()-$startTime;
    4546        $this->queriesCounter++;
    4647    }
     
    5152
    5253    public function getInsertID() {
    53         return $this->dBObject->insert_id;
     54        return $this->dbObject->insert_id;
    5455    }
    5556
     
    7677
    7778    public function getAffectedRows() {
    78         return $this->dBObject->affected_rows;
     79        return $this->dbObject->affected_rows;
    7980    }
    8081
     
    9394        return mysql_escape_string($string);
    9495    }
     96
     97    public function registerDestructFunction($function) {
     98        $this->destructFunctions[] = $function;
     99    }
     100
     101    public function __destruct() {
     102        foreach($this->destructFunctions AS $curFunc)
     103            call_user_func($curFunc);
     104    }
    95105}
    96106
  • trunk/modules/Session.class.php

    r6 r20  
    33class Session extends ModuleTemplate {
    44    protected $requiredModules = array(
    5         'Template',
    6         'DB'
     5        'DB',
     6        'Template'
    77    );
    88
    9     function initializeMe() {
     9    public function initializeMe() {
    1010        session_set_save_handler( // Session-Management auf Datenbank umstellen
    11             array(&$this,'DataHandlerOpen'),
    12             array(&$this,'DataHandlerClose'),
    13             array(&$this,'DataHandlerRead'),
    14             array(&$this,'DataHandlerWrite'),
    15             array(&$this,'DataHandlerDestroy'),
    16             array(&$this,'DataHandlerGc')
     11            array($this,'DataHandlerOpen'),
     12            array($this,'DataHandlerClose'),
     13            array($this,'DataHandlerRead'),
     14            array($this,'DataHandlerWrite'),
     15            array($this,'DataHandlerDestroy'),
     16            array($this,'DataHandlerGc')
    1717        );
    1818        session_name('sid'); // Name der Session zu "sid" aendern
     
    2828        define('MYSID',$mySID);
    2929        $this->modules['Template']->assign('mySID',$mySID);
     30        $this->modules['DB']->registerDestructFunction('session_write_close');
    3031    }
    3132
     
    5960    }
    6061
    61     function DataHandlerDestroy($sessionID) {
     62    public function DataHandlerDestroy($sessionID) {
    6263        $this->modules['DB']->query("DELETE FROM ".TBLPFX."sessions WHERE SessionID='$sessionID'");
    6364        return ($this->modules['DB']->getAffectedRows() == 0) ? FALSE : TRUE;
    6465    }
    6566
    66     function DataHandlerGc($sessionMaxLifeTime) {
     67    public function DataHandlerGc($sessionMaxLifeTime) {
    6768        $this->modules['DB']->query("DELETE FROM ".TBLPFX."sessions WHERE SessionLastUpdate<'".$this->modules['DB']->fromUnixTimestamp(time()-$sessionMaxLifeTime)."'");
    6869
    6970        return TRUE;
    7071    }
    71 
    72     public function __destruct() {
    73         session_write_close();
    74     }
    7572}
    7673
Note: See TracChangeset for help on using the changeset viewer.