DBHandler
class. This
class makes it possible to run queries easily through predefined helper methods. The features and functions
provided through this class are quite important to a level in which they are also extended to database relationships.
Here, we will focus on the basic database operations that can be performed through the database handler class.
DBHandler
class provides some basic methods which makes it easier to perform database operations.
These methods are grouped below based on the operation they perform
$db = (new DB)->openDB();
if($db->table_exists('table_name')) {
//run this code ...
}
$db = (new DB)->openDB();
if($db->column_exists('table_name', 'column_name')) {
//run this code ...
}
$db = (new DB)->openDB();
if($db->addColumn([table_name => column_name], type, pipe, definition, default)) {
where:
table_name : name of table where column will be added
column_name : name of column to be added
type : type of column e.g ( decimal(2,5); varchar(200), e.t.c)
pipe : FIRST | AFTER FIELDNAME (After can be replaced with a pipe e.g "|Email" means AFTER Email )
definition : field definition (e.g NOT NULL, UNIQUE)
default : field default value.
}
1970-01-01 00:00:00
as the default datetime which
still translates as zero.$db = (new DB)->openDB(); if($db->drop(true)) { //currently connected database dropped successfully! } if($db->drop('table_name', true)) { //selected table_name of current database dropped successfully! } if($db->drop('table_name', 'column_name')) { //relative column dropped successfully }
error_exists()
and error()
method must be supplied
an argument of true
in order to function as expected. However DBStatus::err()
will still return
the last error encountered. Errors are discussed below.
DBStatus
helps to keep track of last executed
sql queries and error responses.