diff options
author | Malf Furious <m@lfurio.us> | 2017-01-14 02:26:28 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-01-14 02:26:28 -0500 |
commit | dae3964e7682dcd0d64075dfc28a23c12ef6c52e (patch) | |
tree | e75233885bf7aa5124fb2fe7173058acaf30c504 /app | |
parent | 33499cb813d6aac2abc649dd8e42a3c97ce306b2 (diff) | |
download | scrott-dae3964e7682dcd0d64075dfc28a23c12ef6c52e.tar.gz scrott-dae3964e7682dcd0d64075dfc28a23c12ef6c52e.zip |
Reset working directory for clean Scrott implementation
Diffstat (limited to 'app')
-rw-r--r-- | app/class/database.class.php | 73 | ||||
-rw-r--r-- | app/class/mysql.class.php | 74 |
2 files changed, 0 insertions, 147 deletions
diff --git a/app/class/database.class.php b/app/class/database.class.php deleted file mode 100644 index c7ef65b..0000000 --- a/app/class/database.class.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php - -/* - * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to UNLICENSE - */ - -/* - * This class provides a common interface to a database. Scrott provides - * facilities for interacting with any DBMS that we can use in PHP. To - * provide support for a new DBMS, extend this class and implement the - * abstract functions. Additionally, update the getInstance() function - * in this class so that the new implementation is used under appropriate - * configuration. - */ -abstract class Database -{ - private static $instance = NULL; - protected $db; - - /* - * Return the database instance object, creating it if this is the - * first call to this function. This function will need maintained - * as new DBMSs are supported. - */ - public static function getInstance() : Database - { - // todo - } - - /* - * These functions are to be implemented by DBMS extensions, - * providing a uniform interface to database engines. - */ - public abstract function close(); - public abstract function query(string $query) : array; - public abstract function esc(string $str) : string; - - /* - * This function will lookup the row from the database on the given - * table containing the given GUID and initialize the class properties - * on this object based on the given field list. - */ - public function initObj(string $table, array $fields, string $guid = NULL) - { - if (is_null($guid)) - return; - - $guid = $this->esc($guid); - $query = "SELECT * FROM " . $table . " WHERE guid = '" . $guid . "'"; - $res = $this->query($query); - - if (!count($res)) - return; - - $res = $res[0]; - - foreach ($fields as $field) - { - if (isset($res[$field])) - $this->$field = $res[$field]; - } - } -} - -?> diff --git a/app/class/mysql.class.php b/app/class/mysql.class.php deleted file mode 100644 index 90a4016..0000000 --- a/app/class/mysql.class.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php - -/* - * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to UNLICENSE - */ - -require_once "class/database.class.php"; - -/* - * This class implements support for MySQL and MariaDB via PHP's mysqli - * driver. - */ -class Mysql extends Database -{ - /* - * Constructor - */ - public function __construct(string $host, string $username, string $password, string $dbName) - { - $this->db = new mysqli($host, $username, $password, $dbName); - - if ($this->db->connect_error) - throw new Exception("Can not connect to MySQL database. Please check your configuration."); - } - - /* - * Destructor - */ - public function __destruct() - { - $this->close(); - } - - /* - * Close connection to DB - */ - public function close() - { - $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); - } -} - -?> |