From a13c30a5c380b01c512f820fa515ddeb4691e8fd Mon Sep 17 00:00:00 2001 From: xinatorus Date: Tue, 21 Apr 2020 20:02:46 +0200 Subject: [PATCH] refactoring --- app/class/DB.php | 74 +++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/app/class/DB.php b/app/class/DB.php index 4308385..3921c4a 100644 --- a/app/class/DB.php +++ b/app/class/DB.php @@ -1,4 +1,5 @@ 0 ? count($values)-1 : 0)) . - "?)" - , array_values ($values)); - } - // TODO: pokud vlozim prazdne pole tak chyba ?? - public static function addAll ($table, $values = array ()) { - try { - foreach ($values as $value) { - self::add ($table, $value); - } - } catch (PDOException $ex) { - throw new PDOException ($ex->getMessage()); - } - } + implode('`, `', array_keys($values)) . + "`) VALUES (" . + str_repeat('?,', (count($values) > 0 ? count($values)-1 : 0)) . + "?)" + , array_values ($values) + ); + } + // TODO: pokud vlozim prazdne pole tak chyba ?? + public static function addAll ($table, $values = array ()) { + try { + foreach ($values as $value) { + self::add ($table, $value); + } + } catch (PDOException $ex) { + throw new PDOException ($ex->getMessage()); + } + } - public static function edit ( - $table, - $values = array(), - $conditions, - $values2 = array() - ) { - return self::command ( - "UPDATE `$table` SET `" . - implode('` =?, `', array_keys($values)) . - "` =? " . - $conditions - , array_merge (array_values ($values), $values2)); - } + public static function edit ($table, $values = array(), $conditions, $values2 = array()) { + return self::command ( + "UPDATE `$table` SET `" . + implode('` =?, `', array_keys($values)) . + "` =? " . + $conditions + , array_merge (array_values ($values), $values2) + ); + } - public static function insertId () { - return self::$join->lastInsertId (); - } + public static function insertId () { + return self::$join->lastInsertId (); + } - public static function addId ($lastTable, $lastIdName) { - $answer = self::$join->prepare ("SELECT `$lastIdName` FROM `$lastTable` ORDER BY `$lastIdName` DESC"); - $answer->execute (); - return $answer->fetch (PDO::FETCH_NUM)[0]; - } - } + public static function addId ($lastTable, $lastIdName) { + $answer = self::$join->prepare ("SELECT `$lastIdName` FROM `$lastTable` ORDER BY `$lastIdName` DESC"); + $answer->execute (); + return $answer->fetch (PDO::FETCH_NUM)[0]; + } +}