<?php
namespace Core;

use App\Config;

abstract class Model
{
    protected static $conn = null;

    protected static function connectDB()
    {
        try {
            if (!self::$conn) {
                $dsn = 'mysql:host='.Config::DB_HOST.';dbname='.Config::DB_DB;
                self::$conn = new \PDO($dsn, Config::DB_UNAME, Config::DB_PWD);

                self::$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            }
            return self::$conn;
        } catch (PDOException $e) {
            throw new \Exception($e->getMessage, 444);
        }
    }

    abstract protected function createTable($fields);
    abstract protected function dropTable();

    abstract public function showAll($conditions = []);
    abstract public function entry($args);
    abstract public function update($args, $id);
    abstract public function delete($id, $status);
}
