diff --git a/classes/bfw/database/Database.php b/classes/bfw/database/Database.php --- a/classes/bfw/database/Database.php +++ b/classes/bfw/database/Database.php @@ -12,16 +12,15 @@ use PDOException; class Database implements DBInterface { - private static $logger = null; private static $handle = null; - + private $logger; /** * @var PDO */ private $pdo; private function __construct() { - self::$logger = Logger::getLogger('__CLASS__'); + $this->logger = Logger::getLogger(__CLASS__); $dsn = 'mysql:host=localhost;dbname=ticketsystem'; $config = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); @@ -59,12 +58,11 @@ */ public function cleanup() { try { - $status = $this->pdo->exec("DELETE FROM `t_ticket` WHERE `id` > 1;"); - $status = $this->pdo->exec("DELETE FROM `t_history` WHERE `id` > 1;"); - $status = $this->pdo->exec("DELETE FROM `t_user` WHERE `id` > 2;"); - $status = $this->pdo->exec("ALTER TABLE `t_history` AUTO_INCREMENT = 1;"); - $status = $this->pdo->exec("ALTER TABLE `t_ticket` AUTO_INCREMENT = 1;"); - $status = $this->pdo->exec("ALTER TABLE `t_user` AUTO_INCREMENT = 2;"); + $this->pdo->exec("DELETE FROM `t_user` WHERE `id` > 2;"); + $this->pdo->exec("DELETE FROM `t_group` WHERE `id` > 5;"); + + $this->pdo->exec("ALTER TABLE `t_user` AUTO_INCREMENT = 2;"); + $this->pdo->exec("ALTER TABLE `t_group` AUTO_INCREMENT = 5;"); } catch (PDOException $pdoe) { return false; } @@ -98,7 +96,14 @@ fclose($handle); } + /** + * @param $table + * @param $cond + * @return array|null + */ public function fetchAll($table, $cond) { + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $cond)); + return $this->fetch($table, $cond); } @@ -108,6 +113,8 @@ * @return array|null */ public function fetch($table, $cond) { + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $cond)); + $stmt = $this->pdo->prepare(sprintf(' SELECT * @@ -158,7 +165,14 @@ fclose($handle); } + /** + * @param $table + * @param $id + * @return mixed|null + */ public function find($table, $id) { + $this->logger->info(sprintf('%s(%s, %d) ', __METHOD__, $table, $id)); + $stmt = $this->pdo->prepare( sprintf(' SELECT @@ -180,7 +194,14 @@ return null; } + /** + * @param $table + * @param $sys + * @return array|null + */ public function findAll($table, $sys) { + $this->logger->info(sprintf('%s(%s, %d) ', __METHOD__, $table, $sys)); + $stmt = $this->pdo->prepare( sprintf(' SELECT @@ -202,7 +223,15 @@ return null; } + /** + * @param $table + * @param $field + * @param $value + * @return mixed|null + */ public function findByField($table, $field, $value) { + $this->logger->info(sprintf('%s(%s, %s, %s) ', __METHOD__, $table, $field, $value)); + $stmt = $this->pdo->prepare( sprintf(' SELECT @@ -223,7 +252,15 @@ return null; } + /** + * @param $table + * @param $field + * @param $value + * @return array|null + */ function findAllByField($table, $field, $value) { + $this->logger->info(sprintf('%s(%s, %s, %s) ', __METHOD__, $table, $field, $value)); + $stmt = $this->pdo->prepare( sprintf(' SELECT @@ -244,7 +281,13 @@ return null; } + /** + * @param $sql + * @return array|null + */ public function query($sql) { + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $sql)); + $stmt = $this->pdo->query($sql); if ($stmt) { @@ -254,6 +297,11 @@ return null; } + /** + * @param $table + * @param $array + * @return int + */ public function persist($table, $array) { $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, print_r($array, true))); @@ -283,6 +331,12 @@ return $this->pdo->exec($sql); } + /** + * @param $table + * @param $id + * @param $array + * @return int + */ public function store($table, $id, $array) { $this->logger->info(sprintf('%s(%s, %d, %s) ', __METHOD__, $table, $id, print_r($array, true))); @@ -304,6 +358,11 @@ return $this->pdo->exec($sql); } + /** + * @param $table + * @param $id + * @return int + */ public function delete($table, $id) { $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $id));