What are the recommended versions of PHP and MySQL to use for compatibility and stability?

To ensure compatibility and stability, it is recommended to use PHP version 7.4 or higher and MySQL version 5.7 or higher. These versions have improved performance, security features, and support for modern web development practices. By using the latest versions of PHP and MySQL, you can ensure that your web application runs smoothly and securely.

// Example of checking PHP version
if (version_compare(PHP_VERSION, '7.4', '<')) {
    die('Your PHP version is too old. Please upgrade to PHP 7.4 or higher.');
}

// Example of checking MySQL version
$mysql_version = mysqli_get_server_info($conn);
if (version_compare($mysql_version, '5.7', '<')) {
    die('Your MySQL version is too old. Please upgrade to MySQL 5.7 or higher.');
}