コード例 #1
0
 public static function getAll()
 {
     $con = Connection::getConnectionObject()->getConnection();
     // Check connection
     if (mysqli_connect_errno()) {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }
     $students = array();
     //Make an empty array
     $stmt = $con->prepare('SELECT id,name,index_no,CGPA,rank FROM student ORDER BY rank');
     $stmt->execute();
     $stmt->bind_result($id, $name, $indexNo, $cGPA, $rank);
     while ($stmt->fetch()) {
         $student = new Student();
         $student->id = $id;
         $student->setName($name);
         $student->setIndexNo($indexNo);
         $student->setCGPA($cGPA);
         $student->setRank($rank);
         array_push($students, $student);
         //Push one by one
     }
     $stmt->close();
     return $students;
 }