db::error PHP Method

error() static public method

An internal error handler
static public error ( string $msg = null, boolean $exit = false ) : mixed
$msg string The error/success message to return
$exit boolean die after this error?
return mixed
    static function error($msg = null, $exit = false)
    {
        $connection = self::connection();
        $error = mysql_error() ? @mysql_error($connection) : false;
        $number = mysql_errno() ? @mysql_errno($connection) : 0;
        if (c::get('db.debugging')) {
            if ($error) {
                $msg .= ' -> ' . $error . ' (' . $number . ')';
            }
            if (self::$last_query) {
                $msg .= ' Query: ' . self::$last_query;
            }
        } else {
            $msg .= ' - ' . l::get('db.errors.msg', 'This will be fixed soon!');
        }
        if ($exit || c::get('db.debugging')) {
            die($msg);
        }
        return array('status' => 'error', 'msg' => $msg);
    }

Usage Example

Example #1
0
 public function __construct($dbname, $dbuser, $dbpass, $error = array(NULL, NULL))
 {
     self::$error = new error($error[0], $error[1]);
     $this->json = new Services_JSON();
     $fp = fopen(CWD . "users", "r");
     while (fscanf($fp, "%s\n", $hash)) {
         if ($hash == md5($dbuser . $dbpass)) {
             self::$access = 1;
             break;
         }
         if (self::$access == 0) {
             $this->nouser($dbuser);
         }
     }
     if (self::$access == 1) {
         if (!is_dir(CWD . $dbname)) {
             if (!defined('ADMIN') || ADMIN == 0) {
                 $this->nodb($dbname);
             } else {
                 if (ADMIN == 1) {
                     $this->createdb($dbname);
                 }
             }
         } else {
             self::$db = CWD . $dbname . "/";
         }
     }
 }
All Usage Examples Of db::error