function executeQueryPrepared(&$stmt, &$connection, $findFirst = false) { try { $resultSet = array(); $row = array(); if ($stmt->execute()) { bind_array($stmt, $row); while ($stmt->fetch()) { $res = array(); foreach ($row as $key => $value) { $res[$key] = $value; } $resultSet[] = (object) $res; } $stmt->close(); closeDb($connection); // return the first result only. useful when query for just // a single record if ($findFirst) { $resultSet = count($resultSet) > 0 ? $resultSet[0] : null; } } return $resultSet; } catch (Exception $e) { throw new Exception("db error"); } }
function fetch_all_row() { $args = func_get_args(); $args_count = func_num_args(); if ($args_count == 1) { $sql = $args[0]; } else { $sql = $args[0]; } global $db_host, $db_user, $db_pass, $db_name; $conn = new mysqli($db_host, $db_user, $db_pass, $db_name); if ($conn->connect_errno) { echo T_("<h1>데이터베이스에 연결하던 도중 오류가 발생했습니다.</h1>"); exit; } $conn->query("SET time_zone = '+9:00'"); $stmt = $conn->prepare($sql); if ($args_count != 1) { $sliced = array_slice($args, 1); call_user_func_array(array($stmt, "bind_param"), make_values_referenced($sliced)); } $stmt->execute(); $stmt->store_result(); bind_array($stmt, $row); $array = []; while ($stmt->fetch()) { array_push($array, clone_array($row)); } $stmt->close(); $conn->close(); return $array; }
if ($stmt->num_rows === 0) { $_SESSION['login_error'] = 2; header("Location: index.php"); exit; } else { //Interpret Result function bind_array($stmt, &$row) { $md = $stmt->result_metadata(); $params = array(); while ($field = $md->fetch_field()) { $params[] =& $row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $params); } bind_array($stmt, $row); $stmt->fetch(); $hashedPassword = $row["hashed_password"]; $admin = $row["admin"]; $_SESSION["firstName"] = $row["firstname"]; //Verify Fetched Password && Check if user is an admin if (password_verify($password, $hashedPassword) && $admin == 0) { $_SESSION["logged_in"] = 1; $_SESSION["email"] = $email; record_time($link, $email); header("Location: home.php"); } else { if (password_verify($password, $hashedPassword)) { $_SESSION["logged_in"] = 1; $_SESSION["email"] = $email; $_SESSION['Admin'] = 1;