Compare commits

..

2 Commits

Author SHA1 Message Date
f91a2441d6
add/modify template for audit logger
Some checks failed
soko-web/pipeline/pr-master There was a failure building this commit
2023-04-17 20:39:40 +02:00
3e144a66f3
implement audit logger 2023-04-17 20:39:40 +02:00

View File

@ -19,9 +19,15 @@ class Connection implements IConnection
$socket = (string) ini_get('mysqli.default_socket'); $socket = (string) ini_get('mysqli.default_socket');
} }
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$this->connection = new mysqli($host, $user, $password, $db, $port, $socket); $this->connection = new mysqli($host, $user, $password, $db, $port, $socket);
$this->connection->set_charset('utf8mb4');
if ($this->connection->connect_error) {
throw new \Exception('Connection failed: ' . $this->connection->connect_error);
}
if (!$this->connection->set_charset('utf8mb4')) {
throw new \Exception($this->connection->error);
}
} }
public function __destruct() public function __destruct()
@ -31,24 +37,30 @@ class Connection implements IConnection
public function startTransaction(): void public function startTransaction(): void
{ {
$this->connection->autocommit(false); if (!$this->connection->autocommit(false)) {
throw new \Exception($this->connection->error);
}
} }
public function commit(): void public function commit(): void
{ {
$this->connection->commit(); if (!$this->connection->commit() || !$this->connection->autocommit(true)) {
$this->connection->autocommit(true); throw new \Exception($this->connection->error);
}
} }
public function rollback(): void public function rollback(): void
{ {
$this->connection->rollback(); if (!$this->connection->rollback() || !$this->connection->autocommit(true)) {
$this->connection->autocommit(true); throw new \Exception($this->connection->error);
}
} }
public function query(string $query): ?IResultSet public function query(string $query): ?IResultSet
{ {
$result = $this->connection->query($query); if (!($result = $this->connection->query($query))) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
if ($result !== true) { if ($result !== true) {
return new ResultSet($result); return new ResultSet($result);
@ -59,7 +71,9 @@ class Connection implements IConnection
public function multiQuery(string $query): array public function multiQuery(string $query): array
{ {
$this->connection->multi_query($query); if (!$this->connection->multi_query($query)) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
$ret = []; $ret = [];
do { do {
@ -72,12 +86,18 @@ class Connection implements IConnection
$this->connection->more_results(); $this->connection->more_results();
} while ($this->connection->next_result()); } while ($this->connection->next_result());
if ($this->connection->error) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
return $ret; return $ret;
} }
public function prepare(string $query): IStatement public function prepare(string $query): IStatement
{ {
$stmt = $this->connection->prepare($query); if (!($stmt = $this->connection->prepare($query))) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
return new Statement($stmt); return new Statement($stmt);
} }