1 <?php rcs_id('$Id: DbSession.php,v 1.32 2005-02-11 14:41:57 rurban Exp $');
4 * Store sessions data in Pear DB / ADODB / dba / ....
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.
13 * Warning: Enable USE_SAFE_DBSESSION if you get INSERT duplicate id warnings.
22 * Pear DB handle, or WikiDB object (from which the Pear DB handle will
25 * @param string $table
26 * Name of SQL table containing session data.
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;
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')
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;
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);
56 function currentSessions() {
57 return $this->_backend->currentSessions();
59 function query($sql) {
60 return $this->_backend->query($sql);
62 function quote($string) { return $string; }
65 // $Log: not supported by cvs2svn $
71 // c-hanging-comment-ender-p: nil
72 // indent-tabs-mode: nil