How does PHP handle time zones when interacting with MySQL databases?

When interacting with MySQL databases, PHP can handle time zones by setting the time zone in both PHP and MySQL to ensure consistency in date and time calculations. This can be achieved by setting the time zone in PHP using the date_default_timezone_set() function and configuring MySQL to use the same time zone.

// Set the time zone in PHP
date_default_timezone_set('America/New_York');

// Set the time zone in MySQL
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
$mysqli->query("SET time_zone = 'America/New_York'");