public function get_by_id($id)
 {
     //connect
     $this->db->connect();
     //query
     $sql = "SELECT * FROM students WHERE id=?";
     //prepare
     $stmt = $this->db->initialize($sql);
     //bind
     $stmt->bind_param("i", $id);
     //execute
     $stmt->execute();
     //bind result
     $stmt->bind_result($id, $first_name, $last_name, $email, $contact_no, $course);
     while ($row = $stmt->fetch()) {
         $student = new Students();
         $student->set_id($id);
         $student->set_first_name($first_name);
         $student->set_last_name($last_name);
         $student->set_email($email);
         $student->set_contact_no($contact_no);
         $student->set_course($course);
     }
     $this->db->close();
     return $student;
 }
 private function map_data()
 {
     $student = new Students();
     $student->set_first_name($_POST['first_name']);
     $student->set_last_name($_POST['last_name']);
     $student->set_email($_POST['email']);
     $student->set_contact_no($_POST['contact_no']);
     $student->set_course($_POST['course_id']);
     return $student;
 }
 private function _map_posted_data()
 {
     $students = new Students();
     $students->set_first_name($_POST['first_name']);
     $students->set_last_name($_POST['last_name']);
     $students->set_email($_POST['email']);
     $students->set_contact_no($_POST['contact_no']);
     $students->set_course($_POST['course']);
     return $students;
 }
 public function get_all()
 {
     $student_list = array();
     //database connect
     $this->db->connect();
     //query
     $sql = "SELECT * FROM students";
     //execute and fetch data
     $result = $this->db->fetch_query($sql);
     while ($row = $result->fetch_assoc()) {
         //put in object
         $student = new Students();
         $student->set_id($row['id']);
         $student->set_first_name($row['first_name']);
         $student->set_last_name($row['last_name']);
         $student->set_email($row['email']);
         $student->set_contact_no($row['contact_no']);
         $student->set_course($row['course']);
         array_push($student_list, $student);
     }
     return $student_list;
     $this->db->close;
 }
Beispiel #5
0
<?php

include_once "config.php";
include_once ROOT_PATH . "students/header.php";
require_once ROOT_PATH . "system/models/students.class.php";
require_once ROOT_PATH . "system/dbutil/dbconnection.class.php";
require_once ROOT_PATH . "system/repository/studentrepository.class.php";
$students = new Students();
$students->set_first_name($_POST['first_name']);
$students->set_last_name($_POST['last_name']);
$students->set_email($_POST['email']);
$students->set_contact_no($_POST['first_name']);
$students->set_course($_POST['course']);
$studentrepository = new StudentRepository();
$success = false;
if (isset($_POST['id']) && $_POST['id'] == '') {
    $result = $studentrepository->insert($students);
} else {
    $result = $studentrepository->update($students);
}
if ($result > 0) {
    header("location:index.php?success=true");
} else {
    header("location:index.php?error=true");
}
exit;