What PHP function should be used to access the currently logged-in username for a database query?
To access the currently logged-in username for a database query in PHP, you can use the `$_SESSION` superglobal to store the username after the user logs in. This way, you can retrieve the username from the session whenever you need it for a database query.
// Start the session
session_start();
// Store the username in the session after the user logs in
$_SESSION['username'] = $logged_in_username;
// Retrieve the username from the session for a database query
$username = $_SESSION['username'];
// Use the $username variable in your database query
$query = "SELECT * FROM users WHERE username = '$username'";