<?php
session_start();
ob_start();
class Database{
   private $con;
   private $server   = "localhost";
   private $username = "fnhlbksw_app";  /// root
   private $password = "Coming12341@";  /// ""
   private $dbname   = "fnhlbksw_app";  // db name

   public function connect(){
      try{
         $this->con = new PDO('mysql:host='.$this->server.';dbname='.$this->dbname,$this->username,$this->password);
         $this->con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);


         return $this->con;
         
      }catch(PDOException $e){
         echo 'connection error'. $e->getMessage();
      }
   }

   public function redirect($location){
      return header("location:$location");
   }

   public function checkAcc($account){
      try{
         $stmt = $this->connect()->prepare('select * from users where account_no =:account');
         $stmt->bindParam(':account',$account);
         $stmt->execute();
         if($stmt->rowCount() < 1){
            return true;
         }else{
            false;
         }
      }catch(PDOException $e){
         echo 'error'. $e->getMessage();
      }
   } 

   public static function getTimes(){
      $hour = date('G');
      if ($hour >= 5 && $hour <= 11) {
         return 'Good Morning';
      } elseif ($hour >= 12 && $hour <= 17) {
         return 'Good Afternoon';
      } else {
         return 'Good Evening';
      }
   }
}

?>