本文整理汇总了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];
}
示例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];
}
示例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);
}
}
}
示例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) . '_';
}
示例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];
}
示例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];
}
示例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);
}
}
}
示例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) . "_";
}
示例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;
}
示例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';
}
}
示例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];
}
示例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');
}
}
示例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);
}
示例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;
}
示例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();
}