What are the best practices for checking and enabling PHP modules like PDO in a server environment?

To check and enable PHP modules like PDO in a server environment, you can use the phpinfo() function to view the current configuration and ensure that the required modules are installed and enabled. If PDO is not enabled, you can enable it by editing the php.ini file and uncommenting the line extension=php_pdo_mysql.dll (for MySQL) or extension=php_pdo_pgsql.dll (for PostgreSQL), then restart the web server.

<?php
// Check if PDO is enabled
if (extension_loaded('pdo')) {
    echo 'PDO is enabled';
} else {
    echo 'PDO is not enabled';
}

// Enable PDO in php.ini (uncomment the line below)
// extension=php_pdo_mysql.dll
// extension=php_pdo_pgsql.dll