How can database queries be stored in variables in PHP?

To store database queries in variables in PHP, you can simply assign the query string to a variable. This allows you to reuse the query multiple times or modify it easily. By storing queries in variables, you can make your code more organized and maintainable.

$query = "SELECT * FROM users WHERE id = 1";
$result = mysqli_query($connection, $query);

// You can now use the $query variable to execute the query multiple times or modify it as needed