本文整理汇总了PHP中StudentInfo::generateId方法的典型用法代码示例。如果您正苦于以下问题:PHP StudentInfo::generateId方法的具体用法?PHP StudentInfo::generateId怎么用?PHP StudentInfo::generateId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StudentInfo
的用法示例。
在下文中一共展示了StudentInfo::generateId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: studentSignin
function studentSignin($pdo)
{
$student_info = new StudentInfo();
//$student_id = $student_info->generateId();
$fname = $student_info->firstName();
$lname = $student_info->lastName();
session_unset();
$query = "SELECT * FROM student WHERE student_fname = :fname AND student_lname = :lname";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':fname', $fname);
$stmt->bindParam(':lname', $lname);
$stmt->execute();
if ($student_exists = $stmt->fetch()) {
foreach ($student_exists as $student) {
$_SESSION['user_id'] = $student['student_id'];
$_SESSION['f_name'] = $student['student_fname'];
$_SESSION['l_name'] = $student['student_lname'];
$_SESSION['theme'] = "red";
$_SESSION['rank'] = 1;
}
} else {
$student_id = $student_info->generateId();
$_SESSION['user_id'] = $student_id;
$_SESSION['f_name'] = $fname;
$_SESSION['l_name'] = $lname;
$_SESSION['theme'] = "red";
$_SESSION['rank'] = 1;
$query = "INSERT INTO student (student_id, student_fname, student_lname) VALUES (:student_id, :fname, :lname)";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':student_id', $student_id, PDO::PARAM_INT);
$stmt->bindParam(':fname', $fname);
$stmt->bindParam(':lname', $lname);
$stmt->execute();
//$course_id = rand(1,3);
$query = "SELECT * FROM class";
// This part can just be replaced with a COUNT function
$stmt = $pdo->prepare($query);
$stmt->execute();
$num_classes = $stmt->rowCount();
$classes_enrolled = array();
$classes_enrolled[0] = rand(1, 3);
while (($i = rand(1, 3)) == $classes_enrolled[0]) {
}
$classes_enrolled[1] = $i;
while (($i = rand(1, 3)) == $classes_enrolled[0] || $i == $classes_enrolled[1]) {
}
$classes_enrolled[2] = $i;
for ($i = 0; $i < 3; $i++) {
$query = "INSERT INTO enroll (enroll_student_id, enroll_class_id) VALUES (:student_id, :course_id)";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':student_id', $student_id);
$stmt->bindParam(':course_id', $classes_enrolled[$i]);
$stmt->execute();
}
}
$pdo = null;
}
示例2: studentSignin
function studentSignin()
{
try {
$pdo = new PDO(DB_PDODRIVER . ':host=' . DB_HOST . ';dbname=' . DB_NAME . '', DB_USER, DB_PASS);
} catch (\PDOException $e) {
echo "Connection failed: " . $e->getMessage();
exit;
}
$student_info = new StudentInfo();
//$student_id = $student_info->generateId();
$fname = $student_info->firstName();
$lname = $student_info->lastName();
session_unset();
$query = "SELECT * FROM student WHERE student_fname = :fname AND student_lname = :lname";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':fname', $fname);
$stmt->bindParam(':lname', $lname);
$stmt->execute();
if ($stmt->fetch(PDO::FETCH_ASSOC)) {
while ($student = $stmt->fetch(PDO::FETCH_ASSOC)) {
$_SESSION['user_id'] = $student['student_id'];
$_SESSION['f_name'] = $student['student_fname'];
$_SESSION['l_name'] = $student['student_lname'];
$_SESSION['theme'] = "red";
$_SESSION['rank'] = 1;
}
} else {
$student_id = $student_info->generateId();
$_SESSION['user_id'] = $student_id;
$_SESSION['f_name'] = $fname;
$_SESSION['l_name'] = $lname;
$_SESSION['theme'] = "red";
$_SERVER['rank'] = 1;
$query = "INSERT INTO student (student_id, student_fname, student_lname) VALUES (:student_id, :fname, :lname)";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':student_id', $student_id, PDO::PARAM_INT);
$stmt->bindParam(':fname', $fname);
$stmt->bindParam(':lname', $lname);
$stmt->execute();
//$course_id = rand(1,3);
$query = "SELECT * FROM class";
// This part can just be replaced with a COUNT function
$stmt = $pdo->prepare($query);
$stmt->execute();
$num_classes = $stmt->rowCount();
$classes_enrolled = array();
$classes_enrolled[0] = rand(1, 3);
while (($i = rand(1, 3)) == $classes_enrolled[0]) {
}
$classes_enrolled[1] = $i;
while (($i = rand(1, 3)) == $classes_enrolled[0] || $i == $classes_enrolled[1]) {
}
$classes_enrolled[2] = $i;
for ($i = 0; $i < 3; $i++) {
$query = "INSERT INTO enroll (enroll_student_id, enroll_class_id) VALUES (:student_id, :course_id)";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':student_id', $student_id);
$stmt->bindParam(':course_id', $classes_enrolled[$i]);
$stmt->execute();
}
}
$pdo = null;
}