Mithril as main method

This commit is contained in:
2017-10-25 12:08:41 +07:00
parent 6040809710
commit d1d5ee1b0c
157 changed files with 19593 additions and 716 deletions

View File

@@ -22,7 +22,49 @@ class ApiModel
}
}
public function showAll($conditions = [], $table)
public static function fetch($table, $conditions = [])
{
$sql = "SELECT * FROM {$table}";
if ($conditions) {
$sql .= " WHERE";
foreach ($conditions as $condition) {
$keys[] = $condition[0];
$operators[] = $condition[1];
$values[] = $condition[2];
}
$x = 0;
foreach ($keys as $key) {
$sql .= " $key $operators[$x] ?";
$x++;
if ($x < count($keys)) {
$sql .= " AND";
}
}
}
try {
$con = static::connectDB();
$query = $con->prepare($sql);
if (count($conditions)) {
$x = 1;
foreach ($values as $value) {
$query->bindValue($x, $value);
$x++;
}
}
$query->execute();
return $query->fetch(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}
}
public static function showAll($table, $conditions = [])
{
$sql = "SELECT * FROM {$table}";
@@ -64,7 +106,7 @@ class ApiModel
}
}
public function update($table, $args)
public static function update($table, $args)
{
$sql = "UPDATE {$table} SET";
@@ -96,15 +138,15 @@ class ApiModel
$query->execute();
return $this->showAll([
return self::showAll($table, [
['id', '=', $id]
], $table);
]);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}
}
public function entry($table, $args)
public static function entry($table, $args)
{
$sql = "INSERT INTO {$table}";
@@ -141,7 +183,7 @@ class ApiModel
}
}
public function remove($table, $id)
public static function remove($table, $id)
{
$sql = "UPDATE {$table} SET `status` = 0 WHERE `id` = ?";
try {
@@ -151,7 +193,9 @@ class ApiModel
$query->bindValue(1, $id);
$query->execute();
return true;
return self::showAll($table, [
['id', '=', $id]
]);
} catch (PDOException $e) {
echo "Error: $e->getMessage()";
}