Hệ thống quản lý ngân hàng máu trong php

1 <?php
2 /*
3  * To change
this license header, choose License Headers in Project Properties.
4  * To change
this template file, choose Tools | Templates
5  * and open the template
in the editor.
6  */
7
8 /**
9  * Description of DBConnect
10  *
11  * @author Vaibhav
12  */

13 class
DBConnect {
14     
private $db = NULL;
15
16     
const DB_SERVER = "localhost";
17     
const DB_USER = "root";
18     
const DB_PASSWORD = "";
19     
const DB_NAME = "donor";
20
21     
public function __construct() {
22         $dsn =
'mysql:dbname=' . self::DB_NAME . ';host=' . self::DB_SERVER;
23         
try {
24             $
this->db = new PDO($dsn, self::DB_USER, self::DB_PASSWORD);
25         }
catch (PDOException $e) {
26             
throw new Exception('Connection failed: ' .
27             $e->getMessage());
28         }
29         
return $this->db;
30     }
31     
32     
public function auth(){
33         session_start();
34         
if(! isset($_SESSION['username'])){
35             header(
"Location: http://localhost/BDManagement/admin");
36         }
37     }
38     
39     
public function checkAuth(){
40         session_start();
41         
if(isset($_SESSION['username'])){
42             header(
"Location: http://localhost/BDManagement/admin/home.php");
43         }
44     }
45
46     
public function logout(){
47         session_start();
48         session_destroy();
49         header(
"Location: http://localhost/BDManagement/admin");
50     }
51
52     
public function addEmployee($username,$password,$firstName,$middleName,$lastName,$pcrNumber,$designation,$landline,$mobile,$birthDay){
53         $stmt = $
this->db->prepare("INSERT INTO employees (f_name,m_name,l_name,username,password,b_day,designation,landline,mobile_nr, prc_nr)"
54                 .
"VALUES (?,?,?,?,?,?,?,?,?,?)");
55         
if($stmt->execute([$firstName,$middleName,$lastName,$username,$password,$birthDay,$designation,$landline,$mobile,$pcrNumber]))
56             
return true;
57         
else
58             
return $this->db->errorInfo();
59     }
60     
61     
public function getEmployees(){
62         $stmt = $
this->db->prepare("SELECT * FROM employees");
63         $stmt->execute();
64         
return $stmt->fetchAll();
65     }
66     
67     
public function getEmployeeById($id){
68         $stmt = $
this->db->prepare("SELECT * FROM employees WHERE id=?");
69         $stmt->execute([$id]);
70         
return $stmt->fetchAll();
71     }
72     
73     
public function updateEmployee($id,$username,$password,$firstName,$middleName,$lastName,$designation,$landline,$mobile,$birthDay){
74         $query =
"UPDATE employees SET username=?, password=?,f_name=?,m_name=?,l_name=?,designation=?,landline=?,mobile_nr=?,b_day=? WHERE id=?";
75         $stmt = $
this->db->prepare($query);
76         $flag = $stmt->execute([$username,$password,$firstName,$middleName,$lastName,$designation,$landline,$mobile,$birthDay, $id]);
77         
if($flag){
78             
return true;
79         }
else{
80             
return false;
81         }
82     }
83     
84     
public function remove($id){
85         $stmt = $
this->db->prepare("DELETE FROM employees WHERE id=?");
86         $flag = $stmt->execute([$id]);
87         
if($flag){
88             
return true;
89         }
else{
90             
return false;
91         }
92     }
93     
94 }


Gõ tìm kiếm nhanh...