Compare commits
2 Commits
948b36c80d
...
644197fae8
Author | SHA1 | Date | |
---|---|---|---|
644197fae8 | |||
f43121769b |
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user