]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/DbSession.php
fix for php4 and case-sensitive filesystems
[SourceForge/phpwiki.git] / lib / DbSession.php
1 <?php rcs_id('$Id: DbSession.php,v 1.33 2005-02-27 19:40:36 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     var $_backend;
18     /**
19      * Constructor
20      *
21      * @param mixed $dbh
22      * DB handle, or WikiDB object (from which the 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         // Check for existing DbSession handler
30         $db_type = $dbh->getParam('dbtype');
31         if (isa($dbh, 'WikiDB')) {
32             //$db_type = substr(get_class($dbh),7); // will fail with php4 and case-sensitive filesystem
33             
34             // < 4.1.2 crash on dba sessions at session_write_close(). 
35             // (Tested with 4.1.1 and 4.1.2)
36             // Didn't try postgres sessions.
37             if (!check_php_version(4,1,2) and $db_type == 'dba')
38                 return false;
39
40             @include_once("lib/DbSession/".$db_type.".php");
41             
42             $class = "DbSession_".$db_type;
43             if (class_exists($class)) {
44                 $backend = &$dbh->_backend;
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 // Revision 1.32  2005/02/11 14:41:57  rurban
67 // seperate DbSession classes: less memory, a bit slower
68 //
69
70 // Local Variables:
71 // mode: php
72 // tab-width: 8
73 // c-basic-offset: 4
74 // c-hanging-comment-ender-p: nil
75 // indent-tabs-mode: nil
76 // End:
77 ?>