DBStatus class.
The DBStatus class is the highest level of call as on the DBHandler class. It
has the power to modify the messages returned by the DBHandler class.
Methods which can be called include :
DBStatus::query()
DBStatus::err()
DBStatus::baseErr()
$db = ($dbc = new DB())->openDB();
if( $db ) {
$db->query('select * from users')->read();
// outputs : select * from users
echo DBStatus::query() ;
}
err() method.
$db = ($dbc = new DB)->openDB();
if( $db ) {
$db->query('select *name from users')->read();
if(DBStatus::err()) {
echo DBStatus::err(); // displays error
}
}
err() method can also modify an existing error. It takes a string as parameter.
The value supplied replaces the last stored error if an error exists. However, if a second parameter of true
is defined, then the defined custom error will forcefully overwrite the default response message even if the response is empty.
if( DBStatus::err('some custom error') ) {
print DBStatus::err(); //some custom error
}
DBStatus::err()
will replace the error with 'some custom error'. However if no error previously exists, then
the custom error will not be set.
DBStatus::err('some custom error', true);
DBStatus custom message will force the
DBStatus to set a custom error even if no error exists previously
err() method is capable of modifying the error message returned by the DBStatus
class, if an existing error is modified, we can still retrieve the real or default error returned from an sql query by
calling the DBStatus::baseErr() method which takes no argument. An example is shown below:
if( DBStatus::err('some custom error') ) {
print DBStatus::baseErr(); //default error
print DBStatus::err(); //some custom error
}