本文整理匯總了PHP中Students::set_id方法的典型用法代碼示例。如果您正苦於以下問題:PHP Students::set_id方法的具體用法?PHP Students::set_id怎麽用?PHP Students::set_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Students
的用法示例。
在下文中一共展示了Students::set_id方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_by_id
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;
}
示例2: get_all
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;
}