uw Fri Mar 2 05:58:47 2001 EDT
Modified files:
/php4/pear/Cache/Container db.php
Log:
Bugfixes: expire, encode()/decode(), MySQL data
- the expire date should be saved as a timestamp with
($expire) ? $expire + time() : 0
- always use encode(), decode() for data storage
- the fieldname "data" is a reserved word in old MySQL versions,
changed to "content"
Index: php4/pear/Cache/Container/db.php
diff -u php4/pear/Cache/Container/db.php:1.2 php4/pear/Cache/Container/db.php:1.3
--- php4/pear/Cache/Container/db.php:1.2 Thu Mar 1 11:51:49 2001
+++ php4/pear/Cache/Container/db.php Fri Mar 2 05:58:46 2001
@@ -17,7 +17,7 @@
// | Chuck Hagenbuch <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: db.php,v 1.2 2001/03/01 19:51:49 sbergmann Exp $
+// $Id: db.php,v 1.3 2001/03/02 13:58:46 uw Exp $
require_once 'DB.php';
require_once 'Cache/Container.php';
@@ -27,7 +27,7 @@
*
* CREATE TABLE cache (
* id varchar(32) NOT NULL DEFAULT '',
- * data text NOT NULL DEFAULT '',
+ * content mediumtext NOT NULL DEFAULT '',
* expires int(9) NOT NULL DEFAULT 0,
* changed timestamp(14),
* INDEX(expires),
@@ -35,36 +35,36 @@
* )
*
* @author Sebastian Bergmann <[EMAIL PROTECTED]>
- * @version $Id: db.php,v 1.2 2001/03/01 19:51:49 sbergmann Exp $
+ * @version $Id: db.php,v 1.3 2001/03/02 13:58:46 uw Exp $
* @package Cache
*/
class Cache_Container_db extends Cache_Container {
/**
- * Name of the DB table to store caching data
- *
- * @see Cache_Container_file::$filename_prefix
- */
+ * Name of the DB table to store caching data
+ *
+ * @see Cache_Container_file::$filename_prefix
+ */
var $cache_table = '';
/**
- * PEAR DB dsn to use.
- *
- * @var string
- */
+ * PEAR DB dsn to use.
+ *
+ * @var string
+ */
var $dsn = '';
/**
- * PEAR DB object
- *
- * @var object PEAR_DB
- */
+ * PEAR DB object
+ *
+ * @var object PEAR_DB
+ */
var $db;
/**
- *
- * @param mixed
- */
+ *
+ * @param mixed
+ */
function Cache_Container_db($options)
{
@@ -88,7 +88,7 @@
function fetch($id)
{
- $query = sprintf('SELECT data, expires FROM %s WHERE id = %s',
+ $query = sprintf('SELECT content, expires FROM %s WHERE id = %s',
$this->cache_table,
"'" . $this->db->quoteString($id) . "'");
@@ -100,15 +100,15 @@
$row = $res->fetchRow();
if (is_array($row))
- return array($row['expires'], $row['data']);
+ return array($row['expires'], $this->decode($row['content']));
}
function save($id, $data, $expires = 0)
{
- $query = sprintf('REPLACE INTO %s (data, expires, id) VALUES (%s, %d, %s)',
+ $query = sprintf('REPLACE INTO %s (content, expires, id) VALUES (%s, %d, %s)',
$this->cache_table,
- "'" . $this->db->quoteString(serialize($data)) . "'",
- $expires,
+ "'" . $this->db->quoteString($this->encode(($data))) . "'",
+ ($expires) ? $expires + time() : 0,
"'" . $this->db->quoteString($id) . "'");
$res = $this->db->query($query);
@@ -117,7 +117,8 @@
return new CacheError('DB::query failed: ' . DB::errorMessage($res));
}
}
-
+
+
function delete($id)
{
$query = sprintf('DELETE FROM %s WHERE id = %s',
@@ -129,7 +130,8 @@
if (DB::isError($res))
return new CacheError('DB::query failed: ' . DB::errorMessage($res));
}
-
+
+
function flush()
{
$query = sprintf('DELETE FROM %s', $this->cache_table);
@@ -139,7 +141,8 @@
if (DB::isError($res))
return new CacheError('DB::query failed: ' . DB::errorMessage($res));
}
-
+
+
function idExists($id)
{
$query = sprintf('SELECT id FROM %s WHERE ID = %s',
@@ -159,7 +162,7 @@
return false;
}
}
-
+
function garbageCollection()
{
$query = sprintf('DELETE FROM %s WHERE expires <= %d AND expires > 0',
@@ -172,6 +175,6 @@
return new CacheError('DB::query failed: ' . DB::errorMessage($res));
}
}
-
+
}
-?>
+?>
\ No newline at end of file
--
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]