/** * Manage instance usage of this class */ public static function &getInstance($type = 'base') { if (key_exists($type, self::$dbCache)) { $db = self::$dbCache[$type]; vglobal('adb', $db); return $db; } else { if (key_exists('base', self::$dbCache)) { $db = self::$dbCache['base']; vglobal('adb', $db); return $db; } } $config = self::getDBConfig($type); $db = new self($config['db_type'], $config['db_server'], $config['db_name'], $config['db_username'], $config['db_password'], $config['db_port']); if ($db->database == NULL) { $db->log('Database getInstance: Error connecting to the database', 'error'); $db->checkError('Error connecting to the database'); return false; } else { self::$dbCache[$type] = $db; vglobal('adb', $db); } return $db; }
/** * Manage instance usage of this class */ static function &getInstance() { global $adb; if (!isset($adb)) { $adb = new self(); } if ($adb->database == NULL) { $adb->log('Database getInstance: Error connecting to the database', 'error'); $adb->checkError('Error connecting to the database', true); } return $adb; }
/** * Creates a new Exception object and immediately logs the message. * * @param string $log The log level to immediately log the message to. * If empty, will only log message if log() is * explicitly called. * @param mixed $message The exception message, PEAR_Error object, or * Exception object. * @param integer $code A numeric error code. * * @return IMP_Compose_Exception Exception argument. */ public static function createAndLog() { $e = new self(func_get_arg(1), func_num_args() == 3 ? func_get_arg(2) : null); $e->log(func_get_arg(0)); return $e; }
public static function exception($title, $ex) { $log = new self(); $message = "{$ex->getFile()} @ {$ex->getLine()}\n\n"; $message .= "{$ex->getMessage()} \n\n{$ex->getTraceAsString()}"; $log->log(self::$EXCEPTION, $title, $message); }