- <?php
- class EmployeeModel {
- private $conn;
- public function __construct($host, $username, $password, $database) {
- // Create connection
- $this->conn = new mysqli($host, $username, $password, $database);
- // Check connection
- if ($this->conn->connect_error) {
- die("Connection failed: " . $this->conn->connect_error);
- }
- }
- // Method to add an employee
- public function addEmployee($employee) {
- $stmt = $this->conn->prepare("INSERT INTO Employee (EmployeeID, Name, DateOfBirth, Position, Department, HireDate, Salary, Email, PhoneNumber) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
- $stmt->bind_param("isssssds",
- $employee['EmployeeID'],
- $employee['Name'],
- $employee['DateOfBirth'],
- $employee['Position'],
- $employee['Department'],
- $employee['HireDate'],
- $employee['Salary'],
- $employee['Email'],
- $employee['PhoneNumber']
- );
- $stmt->execute();
- $stmt->close();
- }
- // Method to view all employees
- public function getAllEmployees() {
- $result = $this->conn->query("SELECT * FROM Employee");
- $employees = [];
- while ($row = $result->fetch_assoc()) {
- $employees[] = $row;
- }
- return $employees;
- }
- }
- ?>
[text] R6
Viewer
Editor
You can edit this paste and save as new: