Changed login/logout process

This commit is contained in:
2017-09-08 10:05:42 +07:00
parent 8eb9005642
commit 8956b17434
6 changed files with 148 additions and 212 deletions

View File

@@ -7,10 +7,6 @@ abstract class Model
{
protected static $conn = null;
abstract public function showAll();
abstract public function showSingle($id);
protected static function connectDB()
{
try {
@@ -60,6 +56,62 @@ abstract class Model
}
}
public function showAll($table, $conditions = [])
{
try {
if ($table) {
$db = static::connectDB();
$sql = "SELECT * FROM $table";
if ($conditions) {
$sql .= " WHERE";
foreach ($conditions as $condition) {
$keys[] = $condition[0];
$operators[] = $condition[1];
$values[] = $condition[2];
}
$x = 1;
$i = 0;
foreach ($keys as $key) {
$sql .= " $key $operators[$i] ?";
$i++;
$x++;
if ($x <= count($keys)) {
$sql .= " AND";
}
}
}
$query = $db->prepare($sql);
if ($conditions) {
$x = 1;
foreach ($values as $value) {
$query->bindValue($x, $value);
$x++;
}
}
$query->execute();
if ($query->rowCount() == 1) {
$result = $query->fetch(\PDO::FETCH_ASSOC);
} elseif ($query->rowCount() > 1) {
$result = $query->fetchAll(\PDO::FETCH_ASSOC);
} else {
return false;
}
return $result;
}
return false;
} catch (PDOException $e) {
throw new \Exception($e->getMessage, 444);
}
}
public function entry($table, $args, $values = '')
{
if (count($args)) {
@@ -146,7 +198,7 @@ abstract class Model
try {
$db = static::connectDB();
$result = $this->showAll([
$result = $this->showAll($table, [
['id', '=', $id]
]);