Example #1
0
 /**
  * Check connection to sql server and connect ti server if not connected
  *
  * @param array mixed $config - global config
  * @param $driver_options - PDO driver options
  */
 protected static function check_connection($config = null, $driver_options = null)
 {
     if (!self::$dbc) {
         if (!$config) {
             $config =& $GLOBALS['config'];
         }
         if (!empty($config['db_config'])) {
             $db_config =& $config['db_config'];
         } else {
             throw new rad_exception('db_config not found at config!');
         }
         try {
             $db_config['db_port'] = $db_config['db_port'] ?: 3306;
             self::$dbc = new PDO("{$db_config['db_server']}:host={$db_config['db_hostname']};port={$db_config['db_port']};dbname={$db_config['db_databasename']}", $db_config['db_username'], $db_config['db_password'], $driver_options);
             self::$connected = true;
             self::exec(rad_config::getParam('setNames'));
         } catch (PDOException $e) {
             throw new rad_exception('PDO Error!: ' . $e->getMessage());
         }
     }
 }
Example #2
0
 public static function ErrorHandler($errno, $errstr = '', $errfile = '', $errline = '', $errcontext = '')
 {
     if (!error_reporting()) {
         return;
     }
     //Error suppressed with @ operator
     $errorType = array(E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE', E_STRICT => 'STRICT NOTICE', E_RECOVERABLE_ERROR => 'RECOVERABLE ERROR');
     if (count($errcontext)) {
         $errcontext = count($errcontext) . ' entries';
     }
     if (array_key_exists($errno, $errorType)) {
         $err = $errorType[$errno];
     } else {
         $err = 'CAUGHT EXCEPTION';
     }
     $message = "{$err}[{$errno}]: {$errstr} in file [{$errfile}] at line [{$errline}] context [{$errcontext}]";
     echo $message . "<hr>";
     if (rad_dbpdo::connected()) {
         rad_dblogger::logerr($message);
     } else {
         rad_dblogger::logerr2txt($message);
     }
 }