diff --git a/src/Database/Mysql/Connection.php b/src/Database/Mysql/Connection.php index 4eb622f..6ebf075 100644 --- a/src/Database/Mysql/Connection.php +++ b/src/Database/Mysql/Connection.php @@ -4,6 +4,8 @@ use SokoWeb\Interfaces\Database\IConnection; use SokoWeb\Interfaces\Database\IResultSet; use SokoWeb\Interfaces\Database\IStatement; use mysqli; +use DateTime; +use DateTimeZone; class Connection implements IConnection { @@ -109,5 +111,16 @@ class Connection implements IConnection mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $this->connection = new mysqli($this->host, $this->user, $this->password, $this->db, $this->port, $this->socket); $this->connection->set_charset('utf8mb4'); + $this->connection->query('SET time_zone = \'' . $this->getTimeZone() . '\''); + } + + private function getTimeZone(): string { + $tz = new DateTimeZone(date_default_timezone_get()); + $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC'))); + + $hours = intdiv($offset, 3600); + $minutes = abs(($offset % 3600) / 60); + + return sprintf("%+03d:%02d", $hours, $minutes); } }