/ Published in: PHP
it's still a work in progress. There are a lot of things I would like to do with it, but I think how I have it set up now is pretty good for how i need it.
It's essentially the backbone of a CMS project I have going (PaamayimCMS).
One major feature that I would LOVE to add to it is chainability. I've been looking at the P4A project, and they claim to have a database wrapper that functions in a similar way to jQuery in regards to that.
In due time i suppose.
Expand |
Embed | Plain Text
<?php class DB { //connection variables protected $dbhost = 'localhost'; protected $dbuser = 'root'; protected $dbpass = ''; protected $dbname = 'database'; //normal global resources protected $db = null; /** * Singleton pattern for instantiating the DB class */ { if(!self::$instance) { self::$instance = new DB; } return self::$instance; } protected function __construct() { { exit; } { exit; } $this->db = $db; } /** * simple method for sanitizing SQL query strings. */ public function Clean($string) { { } } /** * DB class method call to the Query child class. * SELECT queries only * Returns number of rows affected. */ public function Query($statement) { return new Query($statement, $this->db); } /** * DB class method call to the Execute child class. * INSERT/UPDATE/DELETE queries only * Returns number of rows affected. */ public function Execute($statement) { return new Execute($statement, $this->db); } /** * Used to get the last inserted record */ public function InsertID() { } public function __destruct() { } } /** * These are separate classes for the reason that I would like * to be able to edit them with as little distruption to the * flow of the parent class as possible. */ /** * Query child class. Used for running SELECT queries. * Called exclusively by the DB parent class in the Query method */ class Query { protected $result; public function __construct($statement, $link) { { exit; } } /** * I dont really like how this class is going so far. its almost * emulating the regular set of mysql_fetch_*() functions. * * So, im going to try and implement some sort of method where * i can specify the fetch action as an argument. * EG. $result = $db->Query($query)->Fetch('object', 'class'); * Or $arr = $db->Query($query)->Fetch('assoc'); */ public function Get($method, $class = null) { $sql_magic = "mysql_fetch_".$method; { return @$sql_magic($this->result, $class); } else { return @$sql_magic($this->result); } } public function NumRows() { } public function __destruct() { } } /** * Execute child class. Used for running INSERT/UPDATE/DELETE queries. * Called exclusively by the DB parent class in the Execute method */ class Execute { public function __construct($statement, $link) { { exit; } } } class Paginate { /** * Adding this so that I can have pagination included in the class * * Its gonna be a bitch though. */ } ?>
You need to login to post a comment.
