Added error handler
This commit is contained in:
@@ -22,39 +22,42 @@ abstract class Model
|
||||
}
|
||||
return self::$conn;
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
throw new \Exception($e->getMessage, 444);
|
||||
}
|
||||
}
|
||||
|
||||
public function createTable($table, $fields = [])
|
||||
{
|
||||
$sql = "CREATE TABLE IF NOT EXISTS {$table} (".implode(',', $fields).") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
try {
|
||||
$sql = "CREATE TABLE IF NOT EXISTS {$table} (".implode(',', $fields).") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
|
||||
$db = static::connectDB();
|
||||
$query = $db->prepare($sql);
|
||||
$db = static::connectDB();
|
||||
$query = $db->prepare($sql);
|
||||
|
||||
if ($query->execute()) {
|
||||
$query->execute();
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
throw new \Exception($e->getMessage(), 444);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dropTable($table)
|
||||
{
|
||||
if (is_array($table)) {
|
||||
if (count($table)) {
|
||||
$table = implode(', ', $table);
|
||||
try {
|
||||
if (is_array($table)) {
|
||||
if (count($table)) {
|
||||
$table = implode(', ', $table);
|
||||
}
|
||||
}
|
||||
}
|
||||
$sql = "DROP TABLE IF EXISTS {$table}";
|
||||
$sql = "DROP TABLE IF EXISTS {$table}";
|
||||
|
||||
$db = static::connectDB();
|
||||
$query = $db->prepare($sql);
|
||||
|
||||
if ($query->execute()) {
|
||||
$db = static::connectDB();
|
||||
$query = $db->prepare($sql);
|
||||
$query->execute();
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
throw new \Exception($e->getMessage(), 444);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function entry($table, $args, $values = '')
|
||||
@@ -115,12 +118,11 @@ abstract class Model
|
||||
}
|
||||
}
|
||||
|
||||
if ($query->execute()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
$query->execute();
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
throw new \Exception($e->getMessage(), 444);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,12 +160,10 @@ abstract class Model
|
||||
}
|
||||
$query->bindValue($x, $id);
|
||||
|
||||
if ($query->execute()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
$query->execute();
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
throw new \Exception($e->getMessage(), 444);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,12 +179,10 @@ abstract class Model
|
||||
$query->bindValue(1, 3);
|
||||
$query->bindValue(2, $id);
|
||||
|
||||
if ($query->execute()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
$query->execute();
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
throw new \Exception($e->getMessage(), 444);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user