connection = new mysqli($host, $user, $password, $db, $port, $socket); $this->connection->set_charset('utf8mb4'); } public function __destruct() { $this->connection->close(); } public function startTransaction(): void { $this->connection->autocommit(false); } public function commit(): void { $this->connection->commit(); $this->connection->autocommit(true); } public function rollback(): void { $this->connection->rollback(); $this->connection->autocommit(true); } public function query(string $query): ?IResultSet { $result = $this->connection->query($query); if ($result !== true) { return new ResultSet($result); } return null; } public function multiQuery(string $query): array { $this->connection->multi_query($query); $ret = []; do { if ($result = $this->connection->store_result()) { $ret[] = new ResultSet($result); } else { $ret[] = null; } $this->connection->more_results(); } while ($this->connection->next_result()); return $ret; } public function prepare(string $query): IStatement { $stmt = $this->connection->prepare($query); return new Statement($stmt); } public function lastId(): int { return $this->connection->insert_id; } public function getAffectedRows(): int { return $this->connection->affected_rows; } }