세션을 설정하고 준비된 명령문에 바인딩하려면 어떻게해야합니까? mysqli의 결과가 이메일의 세션 [ 'email']과 일치 할 수 있도록하려면 어떻게해야합니까? 기본적으로 바인딩php prepared statement 세션을 바인드
public static function getById($email) {
// Initialize session array
$email = $_SESSION['email'];
// Build database query
$sql = "select * from users where email = ?";
// Open database connection
$database = new Database();
// Get instance of statement
$statement = $database->stmt_init();
// Prepare query
if ($statement->prepare($sql)) {
// Bind parameters
$statement->bind_param('s', $email);
// Execute statement
$statement->execute();
// Bind variable to prepared statement
$statement->bind_result($id, $first_name, $last_name, $username, $email, $created, $active);
// Populate bind variables
$statement->fetch();
// Close statement
$statement->close();
}
// Close database connection
$database->close();
// Build new object
$object = new self;
$object->id = $id;
$object->first_name = $first_name;
$object->last_name = $last_name;
$object->username = $username;
$object->email = $email;
$object->created = $created;
$object->active = $active;
return $object;
}
실제로 문제가 무엇인지 이해하지는 않지만 함수에 보내는 매개 변수를 덮어 쓰는 것은 아마도 원하는 것이 아닙니다. – jeroen
스코프 범위 스코프 .. $ _SESSION 슈퍼 변수는 메소드 스코프를 통해 액세스 할 수 없으므로 변수를 전달하고 'session_start();'를 사용하는지 확인하십시오 – KDOT