]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/DbSession.php
dba simplification: no _backend in the subclass
[SourceForge/phpwiki.git] / lib / DbSession.php
1 <?php rcs_id('$Id: DbSession.php,v 1.34 2005-08-07 10:08:33 rurban Exp $');
2
3 /**
4  * Store sessions data in Pear DB / ADODB / dba / PDO, ....
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, dba and PDO classes by Reini Urban.
12  *
13  * Warning: Enable USE_SAFE_DBSESSION if you get INSERT duplicate id warnings.
14  */
15 class DbSession
16 {
17     /**
18      * Constructor
19      *
20      * @param mixed $dbh
21      * DB handle, or WikiDB object (from which the DB handle will
22      * be extracted.
23      *
24      * @param string $table
25      * Name of SQL table containing session data.
26      */
27     function DbSession(&$dbh, $table = 'session') {
28         // Check for existing DbSession handler
29         $db_type = $dbh->getParam('dbtype');
30         if (isa($dbh, 'WikiDB')) {
31             //$db_type = substr(get_class($dbh),7); // will fail with php4 and case-sensitive filesystem
32             
33             // < 4.1.2 crash on dba sessions at session_write_close(). 
34             // (Tested with 4.1.1 and 4.1.2)
35             // Didn't try postgres sessions.
36             if (!check_php_version(4,1,2) and $db_type == 'dba')
37                 return false;
38
39             @include_once("lib/DbSession/".$db_type.".php");
40             
41             $class = "DbSession_".$db_type;
42             if (class_exists($class)) {
43                 // dba has no ->_dbh, so this is used for the session link
44                 $this->_backend = new $class($dbh->_backend->_dbh, $table);
45                 return $this;
46             }
47         }
48         //Fixme: E_USER_WARNING ignored!
49         trigger_error(sprintf(_("Your WikiDB DB backend '%s' cannot be used for DbSession.")." ".
50                               _("Set USE_DB_SESSION to false."),
51                              $db_type), E_USER_WARNING);
52         return false;
53     }
54     
55     function currentSessions() {
56         return $this->_backend->currentSessions();
57     }
58     function query($sql) {
59         return $this->_backend->query($sql);
60     }
61     function quote($string) { return $string; }
62 }
63
64 // $Log: not supported by cvs2svn $
65 // Revision 1.33  2005/02/27 19:40:36  rurban
66 // fix for php4 and case-sensitive filesystems
67 //
68 // Revision 1.32  2005/02/11 14:41:57  rurban
69 // seperate DbSession classes: less memory, a bit slower
70 //
71
72 // Local Variables:
73 // mode: php
74 // tab-width: 8
75 // c-basic-offset: 4
76 // c-hanging-comment-ender-p: nil
77 // indent-tabs-mode: nil
78 // End:
79 ?>