<?php

namespace App\Models;

use PDO;

/**
 * Post model
 *
 * PHP version 5.4
 */
class Classm extends \Core\Model
{

    /**
     * Get all the posts as an associative array
     *
     * @return array
     */
    public static function getdata($query)
    {
        try {
            $db = static::getclassDB();
            $stmt = $db->query($query);
            $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
            return $results;
        } catch (PDOException $e) {
            echo $e->getMessage();
        }
    }
    public static function insert($query)
    {
        try {
            $db = static::getclassDB();
            $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)
    {
        try {
            $db = static::getclassDB();
            $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)
    {
        try {
            $db = static::getclassDB();
            $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::getclassDB();
            return $db;
            } 
            catch (PDOException $e) {
            echo $e->getMessage();
        }
    }
}
