What is the correct way to concatenate date and time strings in PHP for MySQL DateTime storage?

When concatenating date and time strings in PHP for MySQL DateTime storage, it is important to ensure that the date and time formats are compatible with MySQL's DateTime format (YYYY-MM-DD HH:MM:SS). One way to achieve this is by using the DateTime class in PHP to create a DateTime object from the date and time strings, and then formatting it using the `format()` method with the desired format.

$date = "2022-01-01";
$time = "12:00:00";

$datetime = new DateTime($date . ' ' . $time);
$datetime_formatted = $datetime->format('Y-m-d H:i:s');

echo $datetime_formatted;