I’m grabbing user data from the database using:
$stmt = $db->prepare("SELECT usernames FROM login.users WHERE emails = :email");
$stmt->bindValue(":email", $email);
$stmt->execute();
And other fields than usernames (I haven’t gotten around to fixing specifically which ones I’ll be using).
Since I’m grabbing one user’s data, it should return a single row of data. Thus, I can use:
$data = $stmt->fetch(PDO::FETCH_ASSOC);
which will give me an associative array in $data. But how do I then transfer that to $_SESSION?
Array copying in PHP gave me the idea to use:
$_SESSION[$index] = $data[$index];
Or similar, but how would I go about automatically finding what $index was?
I’d really like it if I could change the SELECT statement to include different columns without having to have $_SESSION['columnname'] = $data['columnname'] for every single column.
You could store the whole $data in a single session variable:
Or you could do the following: