What are the best practices for efficiently retrieving multiple configuration settings from a MySQL database in PHP?

When retrieving multiple configuration settings from a MySQL database in PHP, it is best to use a single query to fetch all the settings at once rather than making individual queries for each setting. This can help reduce the number of database calls and improve performance. Additionally, consider caching the settings in memory to avoid repeated database queries.

// Connect to MySQL database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query to retrieve multiple configuration settings
$query = "SELECT setting_name, setting_value FROM configuration_settings";
$result = mysqli_query($connection, $query);

// Fetch settings and store in an array
$settings = array();
while ($row = mysqli_fetch_assoc($result)) {
    $settings[$row['setting_name']] = $row['setting_value'];
}

// Close database connection
mysqli_close($connection);

// Example usage of retrieved settings
echo $settings['site_title'];
echo $settings['logo_url'];