sync timezone for mysql session
All checks were successful
soko-web/pipeline/head This commit looks good

This commit is contained in:
Bence Pőcze 2025-02-20 22:54:12 +01:00
parent d504f1d5bb
commit d78a82c14c
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

View File

@ -4,6 +4,8 @@ use SokoWeb\Interfaces\Database\IConnection;
use SokoWeb\Interfaces\Database\IResultSet; use SokoWeb\Interfaces\Database\IResultSet;
use SokoWeb\Interfaces\Database\IStatement; use SokoWeb\Interfaces\Database\IStatement;
use mysqli; use mysqli;
use DateTime;
use DateTimeZone;
class Connection implements IConnection class Connection implements IConnection
{ {
@ -109,5 +111,16 @@ class Connection implements IConnection
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); 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 = new mysqli($this->host, $this->user, $this->password, $this->db, $this->port, $this->socket);
$this->connection->set_charset('utf8mb4'); $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);
} }
} }