turn on mysqli exceptions
All checks were successful
soko-web/pipeline/pr-master This commit looks good

This commit is contained in:
Bence Pőcze 2023-04-17 20:42:22 +02:00
parent 948b36c80d
commit f43121769b
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

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);
}