Compare commits

..

No commits in common. "644197fae8e185edd9bad003119f2d2ad3d2bd4a" and "948b36c80d324e07339a543d97b9e629487f3a45" have entirely different histories.

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