From: Joe Z. <jz...@us...> - 2004-03-26 21:44:51
|
Update of /cvsroot/bobs/bobs/inc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31807/bobs/inc Modified Files: class_db.php Log Message: Applied Rene's patch to allow db3 or db4. Index: class_db.php =================================================================== RCS file: /cvsroot/bobs/bobs/inc/class_db.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- class_db.php 29 Sep 2002 06:08:01 -0000 1.4 +++ class_db.php 26 Mar 2004 21:33:50 -0000 1.5 @@ -18,6 +18,7 @@ var $db = ''; // holds an array of database pointers var $db_access = ''; // holds information about which type of db connection is open + var $db_type = ''; // the type of dba we use var $key = ''; var $value = ''; var $db_is_last_key = FALSE; // if this is TRUE then $this->key is the last in the db @@ -25,7 +26,6 @@ var $time; // this is a variable to hold information about performance - function database ($config) { // class constructor @@ -40,6 +40,22 @@ $this->session_id = $config["session_id"]; $this->filelinks = $config["filelinks"]; + // check what dba type we should use + $tmpfile = tempnam("/tmp", "BOBS"); + $dbcheck = @dba_open($tmpfile, "c", "db3"); + if ( $dbcheck === FALSE ) { + $dbcheck = @dba_open($tmpfile, "c", "db4"); + if ( $dbcheck === FALSE ) { + echo "Could not create a database of type db3 or db4 (tried both)\n"; + } else { + dba_close($dbcheck); + $this->db_type = "db4"; + } + } else { + dba_close($dbcheck); + $this->db_type = "db3"; + } + return; } @@ -58,12 +74,12 @@ if ( !isset($this->db[$where][$type]) ) { if ( file_exists ($db) ) { if ( is_writeable($db) ) { - $this->db[$where][$type] = dba_open($db, "w", "db3"); + $this->db[$where][$type] = dba_open($db, "w", $this->db_type); } else { - $this->db[$where][$type] = dba_open($db, "r", "db3"); + $this->db[$where][$type] = dba_open($db, "r", $this->db_type); } } else { - $this->db[$where][$type] = dba_open($db, "c", "db3"); + $this->db[$where][$type] = dba_open($db, "c", $this->db_type); } } return; @@ -167,7 +183,7 @@ // this function will clear a database. $db = $this->db_location($where, $type); - $this->db[$where][$type] = dba_open($db, "n", "db3"); + $this->db[$where][$type] = dba_open($db, "n", $this->db_type); return; } |