How can the FROM_UNIXTIME() MySQL function be utilized effectively when working with timestamps in PHP?

When working with timestamps in PHP and MySQL, the FROM_UNIXTIME() function can be utilized effectively to convert a Unix timestamp into a MySQL datetime format. This is useful when storing timestamps in a MySQL database or when retrieving timestamps from the database and displaying them in a human-readable format in PHP.

// Assuming $timestamp is a Unix timestamp
$mysqlDatetime = date('Y-m-d H:i:s', $timestamp); // Convert Unix timestamp to MySQL datetime format

// Inserting the timestamp into a MySQL database
$query = "INSERT INTO table_name (timestamp_column) VALUES (FROM_UNIXTIME($timestamp))";

// Retrieving and displaying the timestamp in a human-readable format
$query = "SELECT FROM_UNIXTIME(timestamp_column) AS formatted_timestamp FROM table_name";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
echo $row['formatted_timestamp'];