]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/DbSession.php
Allow bold, italics or underlined for numbers
[SourceForge/phpwiki.git] / lib / DbSession.php
1 <?php
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     {
29         // Check for existing DbSession handler
30         $db_type = $dbh->getParam('dbtype');
31         if (isa($dbh, 'WikiDB')) {
32             @include_once("lib/DbSession/" . $db_type . ".php");
33
34             $class = "DbSession_" . $db_type;
35             if (class_exists($class)) {
36                 // dba has no ->_dbh, so this is used for the session link
37                 $this->_backend = new $class($dbh->_backend->_dbh, $table);
38                 return $this;
39             }
40         }
41         //Fixme: E_USER_WARNING ignored!
42         trigger_error(sprintf(_("Your WikiDB DB backend ā€œ%sā€ cannot be used for DbSession.") . " " .
43                 _("Set USE_DB_SESSION to false."),
44             $db_type), E_USER_WARNING);
45         return false;
46     }
47
48     function currentSessions()
49     {
50         return $this->_backend->currentSessions();
51     }
52
53     function query($sql)
54     {
55         return $this->_backend->query($sql);
56     }
57
58     function quote($string)
59     {
60         return $string;
61     }
62 }
63
64 // Local Variables:
65 // mode: php
66 // tab-width: 8
67 // c-basic-offset: 4
68 // c-hanging-comment-ender-p: nil
69 // indent-tabs-mode: nil
70 // End: