What are the best practices for inserting current date and time values into a MySQL database using PHP, considering potential differences between local and live servers?

When inserting current date and time values into a MySQL database using PHP, it's important to consider the potential differences between local and live servers in terms of timezones. To ensure consistency, it's recommended to set the timezone explicitly in your PHP script before inserting the date and time values into the database.

// Set the timezone to match the one used by the live server
date_default_timezone_set('UTC');

// Get the current date and time
$currentDateTime = date('Y-m-d H:i:s');

// Insert the current date and time into the database
$query = "INSERT INTO your_table_name (date_time_column) VALUES ('$currentDateTime')";
$result = mysqli_query($connection, $query);

if ($result) {
    echo "Current date and time inserted successfully.";
} else {
    echo "Error inserting current date and time: " . mysqli_error($connection);
}