From 2eed7b082f83630301e51f57ca8394de228a8605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Sun, 18 Aug 2019 21:14:58 -0500 Subject: first commit --- public/system/library/db/mysqli.php | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 public/system/library/db/mysqli.php (limited to 'public/system/library/db/mysqli.php') diff --git a/public/system/library/db/mysqli.php b/public/system/library/db/mysqli.php new file mode 100644 index 0000000..2e40109 --- /dev/null +++ b/public/system/library/db/mysqli.php @@ -0,0 +1,63 @@ +connection = new \mysqli($hostname, $username, $password, $database, $port); + + if ($this->connection->connect_error) { + throw new \Exception('Error: ' . $this->connection->error . '
Error No: ' . $this->connection->errno); + } + + $this->connection->set_charset("utf8"); + $this->connection->query("SET SQL_MODE = ''"); + } + + public function query($sql) { + $query = $this->connection->query($sql); + + if (!$this->connection->errno) { + if ($query instanceof \mysqli_result) { + $data = array(); + + while ($row = $query->fetch_assoc()) { + $data[] = $row; + } + + $result = new \stdClass(); + $result->num_rows = $query->num_rows; + $result->row = isset($data[0]) ? $data[0] : array(); + $result->rows = $data; + + $query->close(); + + return $result; + } else { + return true; + } + } else { + throw new \Exception('Error: ' . $this->connection->error . '
Error No: ' . $this->connection->errno . '
' . $sql); + } + } + + public function escape($value) { + return $this->connection->real_escape_string($value); + } + + public function countAffected() { + return $this->connection->affected_rows; + } + + public function getLastId() { + return $this->connection->insert_id; + } + + public function connected() { + return $this->connection->ping(); + } + + public function __destruct() { + $this->connection->close(); + } +} -- cgit v1.2.3