sbergmann Thu Mar 1 07:42:36 2001 EDT Added files: /php4/pear/Cache/Container cache_container_phplib.php Log: Added Cache Container class for PHPLIB's database abstraction layer DB_Sql. I can't test this right now, but Ulf told me earlier today that it works fine. Index: php4/pear/Cache/Container/cache_container_phplib.php +++ php4/pear/Cache/Container/cache_container_phplib.php <?php // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | [EMAIL PROTECTED] so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Ulf Wendel <[EMAIL PROTECTED]> | // | Sebastian Bergmann <[EMAIL PROTECTED]> | // +----------------------------------------------------------------------+ // // $Id: cache_container_phplib.php,v 1.1 2001/03/01 15:42:36 sbergmann Exp $ require_once("Cache/Container/cache_container.php"); /* CREATE TABLE cache ( id CHAR(32) NOT NULL DEFAULT '', data TEXT NOT NULL DEFAULT '', expires INT(9) NOT NULL DEFAULT 0, changed TIMESTAMP(14), INDEX (expires), PRIMARY KEY (id) ) */ /** * Stores cache data into a database table. * * @author Ulf Wendel <[EMAIL PROTECTED]>, Sebastian Bergmann <[EMAIL PROTECTED]> * @version $Id: cache_container_phplib.php,v 1.1 2001/03/01 15:42:36 sbergmann Exp $ * @package Cache */ class cache_container_phplib extends cache_container { /** * Name of the DB table to store caching data * * @see cache_container_file::$filename_prefix */ var $cache_table = "cache"; /** * PHPLib object * * @var object PEAR_DB */ var $db; /** * Name of the PHPLib DB class to use * * @var string * @see $db_path, $local_path */ var $db_class = ""; /** * Filename of your local.inc * * If empty, "local.inc" is assumed. * * @var string */ var $local_file = ""; /** * Include path for you local.inc * * HINT: If your're not using prepend.php you must * take care that all classes (files) references by you * local.inc are included automatically. So you might * want to write a new local2.inc that only referrs to * the database class (file) you're using and includes all required files! * * @var string path to your local.inc - make sure to add a trailing slash * @see $local_file */ var $local_path = ""; /** * * @param mixed */ function cache_container_phplib($options = "") { if (is_array($options)) $this->setOptions($options, array("db_class", "db_file", "db_path", "local_file", "local_path")); if (!$this->db_class) return new CacheError("No database class specified.", __FILE__, __LINE__); // include the required files include_once($this->local_path . $this->local_file); // create a db object $this->db = new $this->db_class; } // end constructor function fetch($id) { $query = sprintf("SELECT expires, data FROM %s WHERE id = '%s'", $this->cache_table, $id ); $this->db->query($query); if (!$this->db->Next_Record()) return array(NULL, NULL); return array($this->db->f("expires"), $this->decode($this->db->f("data"))); } // end func fetch function save($id, $data, $expires = 0) { $query = sprintf("REPLACE INTO %s (data, expires, id) VALUES ('%s', %d, '%s')", $this->cache_table, $this->encode($data), $expires, $id ); $this->db->query($query); return (boolean)$this->db->affected_rows(); } // end func save function delete($id) { $query = sprintf("DELETE FROM %s WHERE id = '%s'", $this->cache_table, $id ); $this->db->query($query); return (boolean)$this->db->affected_rows(); } // end func delete function flush() { $query = sprintf("DELETE FROM %s", $this->cache_table); $this->db->query($query); return $this->db->affected_rows(); } // end func flush function idExists($id) { $query = sprintf("SELECT id FROM %s WHERE ID = '%s'", $this->cache_table, $id ); } // end func isExists function garbageCollection() { $query = sprintf("DELETE FORM %s WHERE expires <= %d AND expires > 0", $this->cache_table, time() ); #$this->db->query($query); } // end func garbageCollection } // end class cache_container_phplib ?> -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]