Compare commits

..

4 Commits

Author SHA1 Message Date
61da400599
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:59:20 +02:00
e14336f2d8
implement audit logger 2023-04-17 20:59:20 +02:00
644197fae8
Merge pull request 'turn on mysqli exceptions' (#8) from feature/enable-mysqli-exceptions into master
All checks were successful
soko-web/pipeline/head This commit looks good
Reviewed-on: #8
2023-04-17 20:45:53 +02:00
f43121769b
turn on mysqli exceptions
All checks were successful
soko-web/pipeline/pr-master This commit looks good
2023-04-17 20:42:22 +02:00

View File

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