Your IP : 216.73.217.69
<?php
/**
* Dobi System
*
* Terms of use and legal restrictions:
* PLEASE READ THESE TERMS ( www.dobi.pl/doc/license/ ) CAREFULLY BEFORE USING THIS PRODUCT.
* USING THIS PRODUCT INDICATES THAT YOU ACCEPT THESE TERMS.
* IF YOU DO NOT ACCEPT THESE TERMS , DO NOT USE THIS PRODUCT.
*
* PHP 5.1.2 and later
*
* @license www.dobi.pl/doc/license/ Dobi License 1.0
* @copyright Copyright (c) 2005-2006 Michał 'Cube' Daniel ( http://www.dobi.pl )
* @link www.dobi.pl
* @package Dobi Core
* @version 1.0, 2006/08/10 11:57
* @author Michał 'Cube' Daniel cube@dobi.pl
*
*/
class dbConnectCount
{
private $db_arr_key_amount;
private $db_arr_count_amount;
private $db = null;
public function __construct( dbConnect $dbConnect )
{
$this->db = $dbConnect;
}
public function __call( $method, $args)
{
if (method_exists($this->db, $method))
{
switch(count($args))
{
case 0:
return $this->db->$method();
case 1:
return $this->db->$method($args[0]);
case 2:
return $this->db->$method($args[0], $args[1]);
case 3:
return $this->db->$method($args[0], $args[1], $args[2]);
case 4:
return $this->db->$method($args[0], $args[1], $args[2], $args[3]);
case 5:
return $this->db->$method($args[0], $args[1], $args[2], $args[3], $args[4]);
default:
Dobi::exception('dobiException', WARNING, _DOBI_DATABASE_ERR_6_ . ' (' . $method . ')');
}
}
else
{
Dobi::exception('dobiException', FATAL, _DOBI_DATABASE_ERR_7_ . ' (' . $method . ')');
}
}
public function getAmount($key)
{
if (isset($this->db_arr_key_amount[$key]) && $this->db_arr_key_amount[$key] != '')
{
return $this->db_arr_key_amount[$key];
}
$stmt = $this->db->query('SELECT coun_value FROM ' . $this->db->getTable('counter') . ' WHERE coun_key="' . $key . '"');
$row = $stmt->fetch(ASSOC);
$stmt = NULL;
$this->db->close();
if ($row['coun_value'] == NULL)
{
$row['coun_value'] = 0;
Dobi::exception('dobiExcDatabase', NOTICE, _DOBI_DATABASE_ERR_3_ . $key);
}
$this->db_arr_key_amount[$key] = $row['coun_value'];
return $row['coun_value'];
}
public function count( $key, $select = '*', $from = '', $where = '' )
{
if (isset($this->db_arr_count_amount[$key]) && $this->db_arr_count_amount[$key] != '')
{
return $this->db_arr_count_amount[$key];
}
$sql = 'SELECT COUNT(' . $select . ') FROM ' . $this->db->getTable($from);
if ($where != '')
{
$sql .= ' WHERE ' . $where;
}
$stmt = $this->db->query($sql);
$this->db_arr_count_amount[$key] = $stmt->fetchColumn();
$stmt = NULL;
$this->db->close();
return $this->db_arr_count_amount[$key];
}
public function clearCount()
{
$this->db_arr_count_amount = array();
}
public function clearAmount()
{
$this->db_arr_key_amount = array();
}
public function updateCounter($key, $value = 1)
{
$value = (int)$value;
if (substr($value, 0, 1) != '-') $chr = '+';
else $chr = NULL;
$this->db->exec('UPDATE '. $this->db->getTable('counter') .' SET coun_value = coun_value' . $chr . $value . ' WHERE coun_key="' . $key . '"');
}
public function addCounter($key, $value = 0)
{
$value = (int)$value;
$this->db->exec('INSERT INTO '. $this->db->getTable('counter') .' (coun_value, coun_key) VALUES ("' . $value . '", "' . $key . '")');
}
public function deleteCounter($key)
{
$this->db->exec('DELETE FROM '. $this->db->getTable('counter') .' WHERE coun_key="' . $key . '"');
}
}
?>