MySQL PHP Timezone Check
MySQL PHP Timezone Check
To echo the timezone in MySQL and PHP, you can use the following methods:
1. For MySQL
Use the `@@global.time_zone` and `@@session.time_zone` system variables to check the timezone
settings:
sql
If they are set to `'SYSTEM'`, it means MySQL is using the server's operating system timezone.
2. For PHP
You can check the timezone setting in PHP using the `date_default_timezone_get()` function:
php
<?php
echo 'The current PHP timezone is: ' . date_default_timezone_get();
?>
php
<?php
// PHP timezone
echo 'PHP Timezone: ' . date_default_timezone_get() . "\n";
// MySQL timezone
$pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');
$stmt = $pdo->query("SELECT @@global.time_zone AS global_tz, @@session.time_zone AS ses
sion_tz");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 1/2
echo 'MySQL Session Timezone: ' . $result['session_tz'] . "\n";
?>
Notes:
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 2/2