From 92491a36a3f5f02d11b2aa9bf8f3c1418af6e558 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 15 Jan 2017 20:29:14 -0500 Subject: Add mysql class --- app/class/mysql.class.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/class/mysql.class.php (limited to 'app') diff --git a/app/class/mysql.class.php b/app/class/mysql.class.php new file mode 100644 index 0000000..fae09bb --- /dev/null +++ b/app/class/mysql.class.php @@ -0,0 +1,68 @@ +db = new mysqli($host, $uname, $passwd, $dbname); + + if ($this->db->connect_error) + throw new Exception("Can not connect to MySQL database. Please check your configuration."); + } + + /* + * Close connection to DB + */ + public function close() : void + { + $this->db->close(); + } + + /* + * Make a query of the database. Return data as an array of arrays. + */ + public function query(string $query) : array + { + $arr = array(); + $res = $this->db->query($query); + + if ($res === true || $res === false) + return $arr; + + while (($arr[] = $res->fetch_assoc())); + return $arr; + } + + /* + * Escape a string for use in a query + */ + public function esc(string $str) : string + { + return $this->db->real_escape_string($str); + } +} + +?> -- cgit v1.2.3