Trying to set up a flexible API for the root database object. Specific dataset objects would inherit from this. ( php ) ✂
class Database {
protected $host = '…';
protected $pass = '…';
protected $user = 'www';
protected $database;
protected $connection;
protected $tableList = array();
protected $tableFields = array();
public function __construct( $database='(default)' ) { }
// Internal methods used to check data integrity
public function checkFieldsForTable( $fields, $table ) { }
public function fieldExistsInTable( $field, $value, $table ) { }
public function findFieldsForTable( $table ) { }
// Public methods to be used by inherited objects, etc
public function deleteFieldForValueInTable( $field, $value, $table ) { }
public function editFieldsForIdInTable( $fields, $id, $table ) { }
public function fieldsForTableWhere( $fields, $table, $where='', $byIndex='', $addenda='' ) { }
public function insertFieldsIntoTable( $fields, $table ) { }
// The sign that this object is woefully unfinished:
public function rawSQL( $sql ) { }
}
1 class Database { 2 3 protected $host = '…'; 4 protected $pass = '…'; 5 protected $user = 'www'; 6 protected $database; 7 protected $connection; 8 9 protected $tableList = array(); 10 protected $tableFields = array(); 11 12 public function __construct( $database='(default)' ) { } 13 14 // Internal methods used to check data integrity 15 public function checkFieldsForTable( $fields, $table ) { } 16 public function fieldExistsInTable( $field, $value, $table ) { } 17 public function findFieldsForTable( $table ) { } 18 19 // Public methods to be used by inherited objects, etc 20 public function deleteFieldForValueInTable( $field, $value, $table ) { } 21 public function editFieldsForIdInTable( $fields, $id, $table ) { } 22 public function fieldsForTableWhere( $fields, $table, $where='', $byIndex='', $addenda='' ) { } 23 public function insertFieldsIntoTable( $fields, $table ) { } 24 25 // The sign that this object is woefully unfinished: 26 public function rawSQL( $sql ) { } 27 }
Thoughts on ways to improve this? Should there be a default database, or should it simply return false in order to prevent bad assumptions?