<?php
namespace App\Models;
use PDO;
class Homem extends \Core\Model
{
    private static function selectdb()
    {
        if(isset($_SESSION['org_id']))
        {
            if($_SESSION['org_id'] == 1)
            {
                $db = static::gethindumainunaidedDB();
                return $db;
            }
            if($_SESSION['org_id'] == 2)
            {
                $db = static::hinduamaravathipgDB();
                return $db;
            }
            if($_SESSION['org_id'] == 3)
            {
                $db = static::hinduenggDB();
                return $db;
            }
            if($_SESSION['org_id'] == 4)
            {
                $db = static::hindumcaDB();
                return $db;
            }
            if($_SESSION['org_id'] == 5)
            {
                $db = static::hindumanagementDB();
                return $db;
            }
            if($_SESSION['org_id'] == 6)
            {
                $db = static::hindumcomDB();
                return $db;
            }
        }
    }
    public static function getdata($query)
    {
        if(isset($_SESSION['org_id']))
        {
            try {
                $db = static::selectdb();
                $stmt = $db->query($query);
                $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
                return $results;
            } catch (PDOException $e) {
                echo $e->getMessage();
            }
        }
    }
    public static function insert($query)
    {
        if(isset($_SESSION['org_id']))
        {
            try {
            $db = static::selectdb();
            $db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $stmt = $db->exec($query);
            return $stmt;
            } 
            catch (PDOException $e) {
            echo $e->getMessage();
            }
        }
    }
    public static function update($query)
    {
        if(isset($_SESSION['org_id']))
        {
            try {
                $db = static::selectdb();
                $db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                $stmt = $db->exec($query);
                return $stmt;
                } 
                catch (PDOException $e) {
                echo $e->getMessage();
            }
        }
    }
    public static function delete($query)
    {
        if(isset($_SESSION['org_id']))
        {
            try {
                $db = static::selectdb();
                $db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                $stmt = $db->exec($query);
                return $stmt;
                } 
                catch (PDOException $e) {
                echo $e->getMessage();
            }
        }
    }
    public static function dbconn()
    {
        try {
            $db = static::getDB();
            return $db;
            } 
            catch (PDOException $e) {
            echo $e->getMessage();
        }
    }
}
