How can PDO be used to fetch configuration settings from a database in PHP?

To fetch configuration settings from a database using PDO in PHP, you can create a table in your database to store the settings and then use PDO to query this table and retrieve the settings as needed in your PHP application.

// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=your_database', 'username', 'password');

// Prepare and execute a query to fetch configuration settings
$stmt = $pdo->prepare('SELECT setting_name, setting_value FROM configuration_settings');
$stmt->execute();

// Fetch the settings and store them in an associative array
$settings = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $settings[$row['setting_name']] = $row['setting_value'];
}

// Now you can access the configuration settings as needed
echo $settings['site_title'];