]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/DbSession.php
seperate DbSession classes: less memory, a bit slower
[SourceForge/phpwiki.git] / lib / DbSession.php
1 <?php rcs_id('$Id: DbSession.php,v 1.32 2005-02-11 14:41:57 rurban Exp $');
2
3 /**
4  * Store sessions data in Pear DB / ADODB / dba / ....
5  *
6  * History
7  *
8  * Originally by Stanislav Shramko <stanis@movingmail.com>
9  * Minor rewrite by Reini Urban <rurban@x-ray.at> for Phpwiki.
10  * Quasi-major rewrite/decruft/fix by Jeff Dairiki <dairiki@dairiki.org>.
11  * ADODB and dba classes by Reini Urban.
12  *
13  * Warning: Enable USE_SAFE_DBSESSION if you get INSERT duplicate id warnings.
14  */
15 class DbSession
16 {
17     var $_backend;
18     /**
19      * Constructor
20      *
21      * @param mixed $dbh
22      * Pear DB handle, or WikiDB object (from which the Pear DB handle will
23      * be extracted.
24      *
25      * @param string $table
26      * Name of SQL table containing session data.
27      */
28     function DbSession(&$dbh, $table = 'session') {
29         // Coerce WikiDB to PearDB or ADODB.
30         // Todo: adodb/dba handlers
31         $db_type = $dbh->getParam('dbtype');
32         if (isa($dbh, 'WikiDB')) {
33             $backend = &$dbh->_backend;
34             $db_type = substr(get_class($dbh),7);
35             $class = "DbSession_".$db_type;
36             
37             // < 4.1.2 crash on dba sessions at session_write_close(). 
38             // (Tested with 4.1.1 and 4.1.2)
39             // Didn't try postgres sessions.
40             if (!check_php_version(4,1,2) and $db_type == 'dba')
41                 return false;
42
43             @include_once("lib/DbSession/".$db_type.".php");
44             if (class_exists($class)) {
45                 $this->_backend = new $class($backend->_dbh, $table);
46                 return $this->_backend;
47             }
48         }
49         //Fixme: E_USER_WARNING ignored!
50         trigger_error(sprintf(_("Your WikiDB DB backend '%s' cannot be used for DbSession.")." ".
51                               _("Set USE_DB_SESSION to false."),
52                              $db_type), E_USER_WARNING);
53         return false;
54     }
55     
56     function currentSessions() {
57         return $this->_backend->currentSessions();
58     }
59     function query($sql) {
60         return $this->_backend->query($sql);
61     }
62     function quote($string) { return $string; }
63 }
64
65 // $Log: not supported by cvs2svn $
66
67 // Local Variables:
68 // mode: php
69 // tab-width: 8
70 // c-basic-offset: 4
71 // c-hanging-comment-ender-p: nil
72 // indent-tabs-mode: nil
73 // End:
74 ?>