<?php
require_once("config.php");
require_once("class.db.php");
//
class DBUtils
{

    public $conn;
    ///
    public $config;
    ////
    private $service;

    public function __construct($db_name = null)
    {
        $db = new APIDB($db_name);
        $connection = $db->dbConnection();
        $this->conn = $connection;
        $this->config  = new CONFIG();
        $this->service = $db->inService();
    }

    public function isDBInService()
    {
        return $this->service;
    }

    public function runDeleteQuery($table, $condition)
    {
        $query = $this->conn->prepare("DELETE FROM  $table WHERE $condition");
        return $query;
    }

    public function runUpdateQuery($table, $condition)
    {
        $query = $this->conn->prepare("UPDATE  $table WHERE $condition");
        return $query;
    }

    public function runInsertQuery($table, $rows, $values)
    {
        $query = $this->conn->prepare("INSERT INTO  $table($rows) VALUES($values)");
        return $query;
    }

    public function runQuery($sql)
    {
        $query = $this->conn->prepare($sql);
        return $query;
    }

    public function query($sql)
    {
        $stmt = $this->conn->prepare($sql);
        $stmt->execute();
        $results = $stmt->fetchAll();
        return $results;
    }

    public function getAllRows($table)
    {
        $query = $this->conn->prepare("SELECT * FROM  $table ");
        return $query;
    }

    public function getRows($table, $condition)
    {
        $query = $this->conn->prepare("SELECT * FROM  $table WHERE $condition");
        return $query;
    }
}
