當前位置: 首頁>>代碼示例>>PHP>>正文


PHP throw_exception函數代碼示例

本文整理匯總了PHP中throw_exception函數的典型用法代碼示例。如果您正苦於以下問題:PHP throw_exception函數的具體用法?PHP throw_exception怎麽用?PHP throw_exception使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了throw_exception函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: factory

 /**
  * 返回工廠實例,單例模式
  */
 public static function factory($options)
 {
     $options = is_array($options) ? $options : array();
     //隻實例化一個對象
     if (is_null(self::$cacheFactory)) {
         self::$cacheFactory = new cacheFactory();
     }
     $driver = isset($options['driver']) ? $options['driver'] : C("CACHE_TYPE");
     //靜態緩存實例名稱
     $driverName = md5_d($options);
     //對象實例存在
     if (isset(self::$cacheFactory->cacheList[$driverName])) {
         return self::$cacheFactory->cacheList[$driverName];
     }
     $class = 'Cache' . ucwords(strtolower($driver));
     //緩存驅動
     $classFile = HDPHP_DRIVER_PATH . 'Cache/' . $class . '.class.php';
     //加載驅動類庫文件
     if (!require_cache($classFile)) {
         throw_exception("緩存類型指定錯誤,不存在緩存驅動文件:" . $classFile);
     }
     $cacheObj = new $class($options);
     self::$cacheFactory->cacheList[$driverName] = $cacheObj;
     return self::$cacheFactory->cacheList[$driverName];
 }
開發者ID:sxau-web-team,項目名稱:wish-web,代碼行數:28,代碼來源:CacheFactory.class.php

示例2: connect

 /**
  * 連接數據庫方法
  * @access public
  * @throws ThinkExecption
  */
 public function connect($config = '', $linkNum = 0, $force = false)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         // 處理不帶端口號的socket連接情況
         $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
         // 是否長連接
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         if ($pconnect) {
             $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], CLIENT_MULTI_RESULTS);
         } else {
             $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, CLIENT_MULTI_RESULTS);
         }
         if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum]) || C('SPARE_DB_DEBUG')) {
             $errStr = mysql_error();
             $errno = mysql_errno();
             if ($errno == 13047 || C('SPARE_DB_DEBUG')) {
                 if (C('SMS_ALERT_ON')) {
                     Sms::send('mysql超額被禁用,請在SAE日誌中心查看詳情', $errStr, Sms::MYSQL_ERROR);
                 }
                 //[sae]啟動備用數據庫
                 if (C('SPARE_DB_HOST')) {
                     $this->linkID[$linkNum] = mysql_connect(C('SPARE_DB_HOST') . (C('SPARE_DB_PORT') ? ':' . C('SPARE_DB_PORT') : ''), C('SPARE_DB_USER'), C('SPARE_DB_PWD'), true, CLIENT_MULTI_RESULTS);
                     if (!$this->linkID[$linkNum]) {
                         throw_exception('備用數據庫連接失敗');
                     }
                     mysql_select_db(C('SPARE_DB_NAME'), $this->linkID[$linkNum]);
                     //標記使用備用數據庫狀態
                     $this->is_spare = true;
                 } else {
                     throw_exception($errStr);
                 }
             } else {
                 //[sae] 短信預警
                 if (C('SMS_ALERT_ON')) {
                     Sms::send('數據庫連接時出錯,請在SAE日誌中心查看詳情', $errStr, Sms::MYSQL_ERROR);
                 }
                 throw_exception($errStr);
             }
         }
         $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         if ($dbVersion >= '4.1') {
             //使用UTF8存取數據庫 需要mysql 4.1.0以上支持
             mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]);
         }
         //設置 sql_model
         if ($dbVersion > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->linkID[$linkNum]);
         }
         // 標記連接成功
         $this->connected = true;
         // 注銷數據庫連接配置信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
開發者ID:ysking,項目名稱:commlib,代碼行數:65,代碼來源:DbMysql.class.php

示例3: run

 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     if ('think' == $engine) {
         // 采用Think模板引擎
         if ($this->checkCache($_data['file'])) {
             // 緩存有效
             // 分解變量並載入模板緩存
             extract($_data['var'], EXTR_OVERWRITE);
             //載入模版緩存文件
             include C('CACHE_PATH') . md5($_data['file']) . C('TMPL_CACHFILE_SUFFIX');
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 編譯並加載模板文件
             $tpl->fetch($_data['file'], $_data['var']);
         }
     } else {
         // 調用第三方模板引擎解析和輸出
         $class = 'Template' . ucwords($engine);
         if (is_file(CORE_PATH . 'Driver/Template/' . $class . '.class.php')) {
             // 內置驅動
             $path = CORE_PATH;
         } else {
             // 擴展驅動
             $path = EXTEND_PATH;
         }
         if (require_cache($path . 'Driver/Template/' . $class . '.class.php')) {
             $tpl = new $class();
             $tpl->fetch($_data['file'], $_data['var']);
         } else {
             // 類沒有定義
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
 }
開發者ID:yunsite,項目名稱:e-tuan001-com,代碼行數:35,代碼來源:ParseTemplateBehavior.class.php

示例4: __construct

 public function __construct()
 {
     if (!extension_loaded('eAccelerator')) {
         throw_exception('eAccelerator failed to load');
     }
     $this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6) . '_';
 }
開發者ID:norain2050,項目名稱:xingkang,代碼行數:7,代碼來源:cache.eaccelerator.php

示例5: connect

 /**
  * 連接數據庫方法
  * @access public
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         $conn = $pconnect ? 'mssql_pconnect' : 'mssql_connect';
         // 處理不帶端口號的socket連接情況
         $sepr = IS_WIN ? ',' : ':';
         $host = $config['hostname'] . ($config['hostport'] ? $sepr . "{$config['hostport']}" : '');
         $this->linkID[$linkNum] = $conn($host, $config['username'], $config['password']);
         if (!$this->linkID[$linkNum]) {
             throw_exception("Couldn't connect to SQL Server on {$host}");
         }
         if (!empty($config['database']) && !mssql_select_db($config['database'], $this->linkID[$linkNum])) {
             throw_exception("Couldn't open database '" . $config['database']);
         }
         // 標記連接成功
         $this->connected = true;
         //注銷數據庫安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
開發者ID:wjgjb1109,項目名稱:huicms,代碼行數:31,代碼來源:DbMssql.class.php

示例6: connect

 /**
  * 連接數據庫方法
  * @access public
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         $conn = $pconnect ? 'pg_pconnect' : 'pg_connect';
         $this->linkID[$linkNum] = $conn('host=' . $config['hostname'] . ' port=' . $config['hostport'] . ' dbname=' . $config['database'] . ' user=' . $config['username'] . '  password=' . $config['password']);
         if (0 !== pg_connection_status($this->linkID[$linkNum])) {
             throw_exception($this->error(false));
         }
         //設置編碼
         pg_set_client_encoding($this->linkID[$linkNum], C('DB_CHARSET'));
         //$pgInfo = pg_version($this->linkID[$linkNum]);
         //$dbVersion = $pgInfo['server'];
         // 標記連接成功
         $this->connected = true;
         //注銷數據庫安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
開發者ID:cnn007,項目名稱:FHCRM,代碼行數:29,代碼來源:DbPgsql.class.php

示例7: run

 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     $_content = empty($_data['content']) ? $_data['file'] : $_data['content'];
     $_data['prefix'] = !empty($_data['prefix']) ? $_data['prefix'] : C('TMPL_CACHE_PREFIX');
     if ('think' == $engine) {
         // 采用Think模板引擎
         if (!empty($_data['content']) && $this->checkContentCache($_data['content'], $_data['prefix']) || $this->checkCache($_data['file'], $_data['prefix'])) {
             // 緩存有效
             // 分解變量並載入模板緩存
             extract($_data['var'], EXTR_OVERWRITE);
             //載入模版緩存文件
             include C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX');
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 編譯並加載模板文件
             $tpl->fetch($_content, $_data['var'], $_data['prefix']);
         }
     } else {
         // 調用第三方模板引擎解析和輸出
         $class = 'Template' . ucwords($engine);
         if (class_exists($class)) {
             $tpl = new $class();
             $tpl->fetch($_content, $_data['var']);
         } else {
             // 類沒有定義
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
 }
開發者ID:ljhchshm,項目名稱:weixin,代碼行數:30,代碼來源:ParseTemplateBehavior.class.php

示例8: __construct

 public function __construct()
 {
     if (!function_exists("xcache_info")) {
         throw_exception("Xcache failed to load");
     }
     $this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6) . "_";
 }
開發者ID:my1977,項目名稱:shopnc,代碼行數:7,代碼來源:cache.xcache.php

示例9: connect

 /**
  * 連接
  * @access public
  * @param array $options  配置數組
  * @return object
  */
 public static function connect($options = array())
 {
     if (isset($options['type']) && $options['type']) {
         $type = $options['type'];
         unset($options['type']);
     } else {
         //網站配置
         $config = F("Config");
         if ((int) $config['ftpstatus']) {
             $type = 'Ftp';
         } else {
             $type = 'Local';
         }
     }
     //附件存儲方案
     $type = trim($type);
     $class = 'Attachment' . ucwords($type);
     import("Driver.Attachment.{$class}", LIB_PATH);
     if (class_exists($class)) {
         $Atta = new $class($options);
     } else {
         throw_exception('無法加載附件上傳方案:' . $type);
     }
     return $Atta;
 }
開發者ID:NeilFee,項目名稱:vipxinbaigo,代碼行數:31,代碼來源:AttachmentService.class.php

示例10: login

 public function login()
 {
     if (is_empty($this->post->user) || is_empty($this->post->password)) {
         throw_exception("User and Password are required");
     }
     $options['user']['lvl2'] = "one_login";
     $cod['user']['user'] = $this->post->user;
     $cod['user']['password'] = $this->post->password;
     $this->orm->connect();
     $this->orm->read_data(array("user"), $options, $cod);
     $user = $this->orm->get_objects("user");
     #echo $user[0]->get('type');
     $this->orm->close();
     if (is_empty($user)) {
         throw_exception("User or Password Incorrect");
     } else {
         $_SESSION['user']['id'] = $user[0]->get('id');
         $_SESSION['user']['name'] = $user[0]->get('name');
         $_SESSION['user']['user'] = $user[0]->get('user');
         $_SESSION['user']['type'] = $user[0]->get('type');
         $_SESSION['user']['email'] = $user[0]->get('email');
         $this->session = $_SESSION;
         $this->engine->assign('type_warning', 'success');
         $this->engine->assign('msg_warning', "Welcome!");
         $this->temp_aux = 'message.tpl';
     }
 }
開發者ID:ancdiazmo,項目名稱:ghost_mi_version,代碼行數:27,代碼來源:index.php

示例11: connect

 /**
  * Connection database method
  * @access public
  * @throws SenExecption
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $this->linkID[$linkNum] = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport'] ? intval($config['hostport']) : 3306);
         if (mysqli_connect_errno()) {
             throw_exception(mysqli_connect_error());
         }
         $dbVersion = $this->linkID[$linkNum]->server_version;
         // Set the database encoding
         $this->linkID[$linkNum]->query("SET NAMES '" . C('DB_CHARSET') . "'");
         //Setup sql_model
         if ($dbVersion > '5.0.1') {
             $this->linkID[$linkNum]->query("SET sql_mode=''");
         }
         // Mark connection successful
         $this->connected = true;
         //Unregister database security information
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
開發者ID:davidpersson,項目名稱:FrameworkBenchmarks,代碼行數:31,代碼來源:DbMysqli.class.php

示例12: run

 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     $_content = empty($_data['content']) ? $_data['file'] : $_data['content'];
     $_data['prefix'] = !empty($_data['prefix']) ? $_data['prefix'] : C('TMPL_CACHE_PREFIX');
     if ('think' == $engine) {
         //[sae] 采用Think模板引擎
         if (!empty($_data['content']) && $this->checkContentCache($_data['content'], $_data['prefix']) || $this->checkCache($_data['file'], $_data['prefix'])) {
             // 緩存有效
             //[sae],為方便saeCacheBuilder編譯, 模板編譯緩存不分組
             SaeMC::include_file(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), $_data['var']);
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 編譯並加載模板文件
             $tpl->fetch($_content, $_data['var'], $_data['prefix']);
         }
     } else {
         // 調用第三方模板引擎解析和輸出
         $class = 'Template' . ucwords($engine);
         if (class_exists($class)) {
             $tpl = new $class();
             $tpl->fetch($_content, $_data['var']);
         } else {
             // 類沒有定義
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
     //[sae] 添加trace信息。
     if (!SAE_RUNTIME) {
         trace($_SERVER['HTTP_APPVERSION'] . '/' . RUNTIME_FILE, '核心緩存Mecache KEY', 'SAE');
         trace($_SERVER['HTTP_APPVERSION'] . '/' . C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), '模版緩存Mecache KEY', 'SAE');
     }
 }
開發者ID:jackycgq,項目名稱:extend,代碼行數:33,代碼來源:ParseTemplateBehavior.class.php

示例13: agregar

 public function agregar()
 {
     $parque = new parque($this->post);
     if (is_empty($parque->get('codigo'))) {
         throw_exception("Debe ingresar un codigo");
     }
     if ($parque->get("nivel") == "alto" || $parque->get("nivel") == "bajo") {
     } else {
         throw_exception("El nivel debe de ser alto o bajo");
     }
     if ($parque->get("municipio") == "medellin" || $parque->get("municipio") == "rionegro" || $parque->get("municipio") == "la estrella" || $parque->get(" municipio") == "copacabana" || $parque->get(" municipio") == "guatape") {
     } else {
         throw_exception("El municipio debe de ser medellin, rionegro, la estrella, copacabana o guatape");
     }
     print_r($parque);
     $this->orm->connect();
     $this->orm->insert_data("normal", $parque);
     $this->orm->close();
     settype($data, 'object');
     $data->fecha = date("y-m-d");
     $data->calificacion = 0;
     $data->parque = $parque->get("codigo");
     $calificacion = new calificacion($data);
     $this->orm->connect();
     $this->orm->insert_data("normal", $calificacion);
     $this->orm->close();
     $this->type_warning = "sucess";
     $this->msg_warning = "parque agregado correctamente";
     $this->temp_aux = 'message.tpl';
     $this->engine->assign('type_warning', $this->type_warning);
     $this->engine->assign('msg_warning', $this->msg_warning);
 }
開發者ID:Gonzo107,項目名稱:Parcial2AndresGonzalez,代碼行數:32,代碼來源:c_agregar_parque.php

示例14: CheckCache

/**
+----------------------------------------------------------
* 緩存檢查
* 緩存目錄創建、目錄權限檢查
+----------------------------------------------------------
* @access private 
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
function CheckCache()
{
    //檢測模版緩存目錄,並嘗試創建
    if (!file_exists(CACHE_PATH)) {
        if (!@mkdir(CACHE_PATH)) {
            throw_exception(L('模版緩存目錄不存在:') . CACHE_PATH);
        }
    }
    //檢測數據緩存目錄,並嘗試創建
    if (!file_exists(TEMP_PATH)) {
        if (!@mkdir(TEMP_PATH)) {
            throw_exception(L('數據緩存目錄不存在:') . TEMP_PATH);
        }
    }
    //檢測靜態緩存目錄,並嘗試創建
    if (!file_exists(HTML_PATH)) {
        if (!@mkdir(HTML_PATH)) {
            throw_exception(L('靜態緩存目錄不存在:') . HTML_PATH);
        }
    }
    //檢測日誌目錄,並嘗試創建
    if (!file_exists(LOG_PATH)) {
        if (!@mkdir(LOG_PATH)) {
            throw_exception(L('日誌目錄不存在:') . LOG_PATH);
        }
    }
    return;
}
開發者ID:skiman100,項目名稱:thinksns,代碼行數:38,代碼來源:checkDir.php

示例15: __construct

	public function __construct(){
		$this->config = C('memcache');
		if (!extension_loaded('memcache') || !is_array($this->config[1])) {
			throw_exception('memcache failed to load');
		}
		$this->init();
	}
開發者ID:noikiy,項目名稱:ejia,代碼行數:7,代碼來源:cache.memcache.php


注:本文中的throw_exception函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。