public function index()
 {
     $a = $_GET['a'];
     if (empty($a)) {
         E('参数错误');
     }
 }
예제 #2
0
 /**
  * 连接数据库方法
  * @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='******'username'] . '  password='******'password']);
         if (0 !== pg_connection_status($this->linkID[$linkNum])) {
             E($this->error(false));
         }
         //设置编码
         pg_set_client_encoding($this->linkID[$linkNum], $config['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];
 }
예제 #3
0
 public function check()
 {
     if (!$this->config['email'] || !$this->config['key'] || !$this->config['partner']) {
         E("支付宝设置有误!");
     }
     return true;
 }
예제 #4
0
 public function index()
 {
     try {
         //获取文章信息
         $article_id = I("get.article_id");
         if (!$article_id) {
             E("编号丢失");
         }
         $model_article = D("WxArticle");
         $info = $model_article->where("id = {$article_id}")->find();
         //初始化jssdk信息
         import("Think.WX.jssdk");
         $this->jssdk = new \JSSDK($this->getAppid(), $this->getAppsecret());
         $signPackage = $this->jssdk->GetSignPackage();
         //关注连接
         $subscribe_url = $this->model_config->val("subscribe_url");
         $web = $this->model_config->val("web");
         $this->assign("info", $info);
         $this->assign("subscribe_url", $subscribe_url);
         $this->assign("signPackage", $signPackage);
         $this->assign("uid", $this->user['uid']);
         $this->assign("web", $web);
         $this->display("index");
     } catch (\Exception $e) {
         $this->layer_alert($e->getMessage());
     }
 }
예제 #5
0
 public function login()
 {
     if (!IS_POST) {
         E('无效的页面');
     }
     $Verify = new \Think\Verify();
     //if(!$Verify->check($code)) $this->error('验证码错误');
     $db = M('login');
     $user = $db->where(array('username' => I('username')))->find();
     if (!$user || $user['password'] != I('password', '', md5)) {
         $this->error('账号或密码错误');
     }
     //更新最后一次登录时间及IP
     $data = array('id' => $user['id'], 'logintime' => time(), 'loginip' => get_client_ip());
     $db->save($data);
     session('uid', $user['id']);
     session('username', $user['username']);
     session('name', $user['name']);
     session('logintime', date('Y-m-d H:i:s', $user['logintime']));
     session('loginip', $user['loginip']);
     if ($user['jd'] == '1') {
         session('admin', '1');
     } else {
         session('admin', '0');
     }
     if (I('username') == 'admin') {
         session('iadmin', 1);
     } else {
         session('iadmin', 0);
     }
     $this->redirect('/Home/Index/index');
 }
 public function create_product_template()
 {
     $name = I('post.name');
     $code = I('post.code');
     $price = I('post.price', 0);
     $category = I('post.category');
     $type = I('post.type', 'product');
     $attributes = I('post.attributes/a');
     $description = I('post.description');
     //判断传进来的参数格式的正确性
     if (empty($product_template_name) || empty($product_template_category) || empty($default_code)) {
         E(201, 'parameters error');
     }
     //拼装路径
     $parent_path = substr($product_template_category, strrpos($product_template_category, ',') + 1);
     $product_template_category = substr($product_template_category, 0, strrpos($product_template_category, ','));
     //判断相对应的分类是否存在
     $category_array = explode(",", $product_template_category);
     //获得最后一级分类的id号
     $category_id = $this->modoo_category->create_category_by_path($parent_path, $product_template_category);
     //查看对应的属性值是否存在
     $attributes = $this->modoo_product_attribute->attribute_name_value_isset($attributes, false);
     //创建产品模版,并返回该产品模版的编号
     $product_template_infomation = $this->modoo_product_template->create_product_template($product_template_name, $type, $description, $price, $attributes, $category_id, $default_code);
     //判断是否创建成功
     if (is_numeric($product_template_infomation)) {
         E(0, 'create product template sucess', array('id' => $product_template_infomation));
     } else {
         E(401, 'create product template error', array('message' => $product_template_infomation));
     }
 }
 /**
  * 连接数据库方法
  * @access public
  * @throws ThinkExecption
  */
 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()) {
             E(mysqli_connect_error());
         }
         $dbVersion = $this->linkID[$linkNum]->server_version;
         // 设置数据库编码
         $this->linkID[$linkNum]->query("SET NAMES '" . $config['charset'] . "'");
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             $this->linkID[$linkNum]->query("SET sql_mode=''");
         }
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
예제 #8
0
 /**
  * 设置支付驱动
  * @param string $class 驱动类名称
  */
 private function setDriver($class, $config)
 {
     $this->payer = new $class($config);
     if (!$this->payer) {
         E("不存在支付驱动:{$class}");
     }
 }
예제 #9
0
 /**
  * 连接会员系统
  * @param type $name 服务名
  * @param type $options 参数
  * @return \Libs\Service\class
  */
 public static function connect($name = '', $options = array())
 {
     if (false == isModuleInstall('Member')) {
         return new Passport($options);
     }
     if (empty($options['type'])) {
         //网站配置
         $config = cache("Member_Config");
         if ($config['interface']) {
             $type = $config['interface'];
         } else {
             $type = 'Local';
         }
     } else {
         $type = $options['type'];
     }
     //附件存储方案
     $class = strpos($type, '\\') ? $type : 'Libs\\Driver\\Passport\\' . ucwords(strtolower($type));
     if (class_exists($class)) {
         $connect = new $class($options);
     } else {
         E("通行证驱动 {$class} 不存在!");
     }
     return $connect;
 }
예제 #10
0
 /**
  * @copydoc ExtendedSaver::setData
  */
 public function setData(Data $data)
 {
     parent::setData($data);
     if (!$data->getFieldByName('news_segment')->getRowData(0)) {
         $f = new Field('news_segment');
         $translitedTitle = Translit::asURLSegment($data->getFieldByName('news_title')->getRowData(0));
         $filter = array();
         $pkF = $this->getData()->getFieldByName($this->getPK());
         if ($pkF = $pkF->getRowData(0)) {
             $filter[$this->getPK()] = $pkF;
         }
         for ($i = 0; $i < 30; $i++) {
             $tempTitle = $translitedTitle;
             if ($i) {
                 $tempTitle = $translitedTitle . '-' . $i;
             }
             $filter = array('news_segment' => $tempTitle);
             if (!$this->dbh->getScalar($this->getTableName(), 'news_segment', $filter)) {
                 break;
             } else {
                 $tempTitle = $translitedTitle . '-' . $i;
             }
         }
         $translitedTitle = $tempTitle;
         for ($i = 0, $l = sizeof(E()->getLanguage()->getLanguages()); $i < $l; $i++) {
             $f->setRowData($i, $translitedTitle);
         }
         $data->addField($f);
     }
 }
예제 #11
0
 /**
  * 生成接口参数xml
  */
 function createXml()
 {
     //检测必填参数
     if ($this->parameters["out_trade_no"] == null) {
         E("缺少统一支付接口必填参数out_trade_no!" . "<br>");
     } elseif ($this->parameters["body"] == null) {
         E("缺少统一支付接口必填参数body!" . "<br>");
     } elseif ($this->parameters["total_fee"] == null) {
         E("缺少统一支付接口必填参数total_fee!" . "<br>");
     } elseif ($this->parameters["notify_url"] == null) {
         E("缺少统一支付接口必填参数notify_url!" . "<br>");
     } elseif ($this->parameters["trade_type"] == null) {
         E("缺少统一支付接口必填参数trade_type!" . "<br>");
     } elseif ($this->parameters["trade_type"] == "JSAPI" && $this->parameters["openid"] == NULL) {
         E("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!" . "<br>");
     }
     $this->parameters["appid"] = C('WX_APPID');
     //公众账号ID
     $this->parameters["mch_id"] = C('WX_MCHID');
     //商户号
     $this->parameters["spbill_create_ip"] = $_SERVER['REMOTE_ADDR'];
     //终端ip
     $this->parameters["nonce_str"] = $this->createNoncestr();
     //随机字符串
     $this->parameters["sign"] = $this->getSign($this->parameters);
     //签名
     return $this->arrayToXml($this->parameters);
 }
예제 #12
0
 /**
  * @param array $config Configurations.
  * @param bool $return
  */
 public function __construct($config, $return = false)
 {
     $this->appId = $config['appId'];
     $this->appPublic = $config['public'];
     $this->appSecret = $config['secret'];
     $this->callbackUrl = ($base = E()->getSiteManager()->getCurrentSite()->base) . 'auth.php?okAuth&return=' . (!$return ? $base : $return);
 }
예제 #13
0
 /**
  * Show result.
  */
 protected function showResult()
 {
     list($formID) = $this->getStateParams();
     E()->getRequest()->shiftPath(2);
     $this->results = $this->document->componentManager->createComponent('form', 'Energine\\forms\\components\\FormResults', array('form_id' => $formID));
     $this->results->run();
 }
예제 #14
0
function http($url, $params, $method = 'GET', $header = array(), $multi = false)
{
    $ch = curl_init();
    $opts = array(CURLOPT_TIMEOUT => 30, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HTTPHEADER => $header);
    switch (strtoupper($method)) {
        case 'GET':
            $opts[CURLOPT_URL] = $url . '?' . http_build_query($params);
            break;
        case 'POST':
            $params = $multi ? $params : http_build_query($params);
            $opts[CURLOPT_URL] = $url;
            $opts[CURLOPT_POST] = 1;
            $opts[CURLOPT_POSTFIELDS] = $params;
            break;
        default:
            E('不支持的请求方式!');
    }
    curl_setopt_array($ch, $opts);
    $output = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);
    if ($error) {
        exit('请求发生错误:' . $error);
    }
    return $output;
}
예제 #15
0
 /**
  * @copydoc IBuilder::build
  *
  * @throws SystemException 'ERR_DEV_NO_DATA_DESCRIPTION'
  */
 public function build()
 {
     $result = false;
     if (!$this->dataDescription) {
         throw new SystemException('ERR_DEV_NO_DATA_DESCRIPTION', SystemException::ERR_DEVELOPER);
     }
     foreach ($this->dataDescription as $fieldName => $fieldInfo) {
         $result['meta'][$fieldName] = ['title' => $fieldInfo->getPropertyValue('title'), 'type' => $fieldInfo->getType(), 'key' => $fieldInfo->getPropertyValue('key') && $fieldInfo->getPropertyValue('index') == 'PRI' ? true : false, 'visible' => true, 'name' => $fieldInfo->getPropertyValue('tableName') . "[{$fieldName}]", 'rights' => $fieldInfo->getRights(), 'field' => $fieldName, 'sort' => $fieldInfo->getPropertyValue('sort')];
     }
     if (!$this->data->isEmpty()) {
         for ($i = 0; $i < $this->data->getRowCount(); $i++) {
             foreach ($this->dataDescription as $fieldName => $fieldInfo) {
                 $fieldValue = null;
                 if ($this->data->getFieldByName($fieldName)) {
                     $fieldValue = $this->data->getFieldByName($fieldName)->getRowData($i);
                     if (is_null($fieldValue)) {
                         $fieldValue = '';
                     }
                     if ($fieldName == 'upl_publication_date') {
                         if (!empty($fieldValue)) {
                             $fieldValue = E()->Utils->formatDate($fieldValue, $fieldInfo->getPropertyValue('outputFormat'), FieldDescription::FIELD_TYPE_DATETIME);
                         }
                     }
                 }
                 $result['data'][$i][$fieldName] = $fieldValue;
             }
         }
     }
     $result['breadcrumbs'] = $this->breadcrumbs;
     $result['result'] = true;
     $result['mode'] = 'select';
     $this->result = $result;
     return true;
 }
예제 #16
0
파일: imagick.php 프로젝트: 4u4v/think
 /**
  * 构造方法,可用于打开一张图像
  * @param string $imgname 图像路径
  */
 public function __construct($imgname = null)
 {
     if (!extension_loaded('Imagick')) {
         E(L('_NOT_SUPPERT_') . ':Imagick');
     }
     $imgname && $this->open($imgname);
 }
예제 #17
0
 protected function main()
 {
     $id = !($id = $this->getParam('id')) ? $this->document->getID() : $id;
     $this->setBuilder(new SimpleBuilder());
     $dd = new DataDescription();
     if ($this->getConfig()->getCurrentStateConfig() && $this->getConfig()->getCurrentStateConfig()->fields) {
         $dd->loadXML($this->getConfig()->getCurrentStateConfig()->fields);
     } else {
         $dd->load(['Id' => ['type' => FieldDescription::FIELD_TYPE_INT], 'Name' => ['type' => FieldDescription::FIELD_TYPE_STRING], 'Title' => ['type' => FieldDescription::FIELD_TYPE_STRING], 'HtmlTitle' => ['type' => FieldDescription::FIELD_TYPE_STRING], 'DescriptionRtf' => ['type' => FieldDescription::FIELD_TYPE_HTML_BLOCK]]);
     }
     $fd = new FieldDescription('Url');
     $fd->setType(FieldDescription::FIELD_TYPE_STRING);
     $dd->addFieldDescription($fd);
     $info = E()->getMap()->getDocumentInfo($id);
     $d = new Data();
     $info['Id'] = $id;
     $info['Url'] = E()->getMap()->getURLByID($id);
     $d->load([$info]);
     $this->setDataDescription($dd);
     $this->setData($d);
     $m = new AttachmentManager($this->getDataDescription(), $this->getData(), 'share_sitemap', true);
     $m->createFieldDescription();
     $m->createField('smap_id', false, $id);
     $this->addToolbar($this->loadToolbar());
     $this->js = $this->buildJS();
 }
예제 #18
0
 public function check()
 {
     if (!$this->config['appid'] || !$this->config['mch_id'] || !$this->config['key'] || !$this->config['notify_url']) {
         E("微信支付设置有误!");
     }
     return true;
 }
 /**
  * 自动定位模板文件
  * @access protected
  * @param string $template 模板文件规则
  * @return string
  */
 public function parseTemplate($template = '')
 {
     $plugin = $this->name;
     $plugin_config = $this->config;
     $theme = $plugin_config['theme'];
     $depr = "/";
     if (empty($theme)) {
         $theme = "";
     } else {
         $theme = $depr . $theme;
     }
     $template = str_replace(':', $depr, $template);
     // 分析模板文件规则
     if ('' == $template) {
         // 如果模板文件名为空 按照默认规则定位
         $template = "/" . PLUGIN_CONTROLLER_NAME . $depr . PLUGIN_ACTION_NAME;
     } elseif (false === strpos($template, '/')) {
         $template = "/" . PLUGIN_CONTROLLER_NAME . $depr . $template;
     }
     $v_layer = C("DEFAULT_V_LAYER");
     $file = "./plugins/{$plugin}/{$v_layer}" . $theme . $template . C('TMPL_TEMPLATE_SUFFIX');
     if (!is_file($file)) {
         E(L('_TEMPLATE_NOT_EXIST_') . ':' . $file);
     }
     return $file;
 }
예제 #20
0
파일: DbProvider.php 프로젝트: gtyd/jira
 public function fetch($route, $param = [])
 {
     $arr = explode('/', $route);
     $module = $dal_class = $method = '';
     switch (count($arr)) {
         case 2:
             $dal_class = ucfirst($arr[0]);
             $method = $arr[1];
             $className = "\\dals\\" . $dal_class . "DAL";
             break;
         case 3:
             $module = $arr[0];
             $dal_class = ucfirst($arr[1]);
             $method = $arr[2];
             $className = "\\dals\\" . $module . "\\" . $dal_class . "DAL";
             break;
     }
     static $DAL_Instances = [];
     $className_slave = $this->enableSlaves ? 'slave' : 'master';
     $md5_classname = md5($this->orgcode . '_' . $className . '_' . $className_slave);
     if (isset($DAL_Instances[$md5_classname])) {
         $Instance = $DAL_Instances[$md5_classname];
     } else {
         $Instance = new $className($this->orgcode, $this->enableSlaves);
         $DAL_Instances[$md5_classname] = $Instance;
     }
     //检查参数
     $this->_chkParam($param);
     if (!method_exists($Instance, $method)) {
         throw E("DAL[" . $className . "]方法[" . $method . "]不存在", 100012);
     }
     return call_user_func_array(array($Instance, $method), $param);
 }
예제 #21
0
 /**
  * 模板库删除控制器
  */
 public function delete()
 {
     if (!IS_POST) {
         E('无效的页面');
     }
     $delid = I('delid');
     $db = M('zxmb');
     // $where = array('id'=>$id);
     // $select = $db->field('suolue,yetou,dianzhao,beijing,datu,orther')->where($where)->select();
     // foreach ($select as $v) {
     // 	foreach ($v as $k) {
     // 		$file = 'Public'.$k;
     // 		echo $file .'<br>';
     // 		// unlink($file);
     // 	}
     // }
     foreach ($delid as $v) {
         $select = $db->field('suolue,yetou,dianzhao,beijing,datu,orther')->where("id={$v}")->select();
         foreach ($select as $j) {
             foreach ($j as $k) {
                 $file = 'Public' . $k;
                 unlink($file);
             }
         }
         $result = $db->where("id={$v}")->delete();
     }
     if ($result) {
         $this->success('删除成功', U('/Admin/Index/index'));
     } else {
         $this->error('删除失败');
     }
 }
예제 #22
0
 /**
  * 连接数据库方法
  * @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]) {
             E("Couldn't connect to SQL Server on {$host}");
         }
         if (!empty($config['database']) && !mssql_select_db($config['database'], $this->linkID[$linkNum])) {
             E("Couldn't open database '" . $config['database']);
         }
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
예제 #23
0
function B($b, $c)
{
    ?>
Q<?php 
    echo $g;
    echo E('T');
}
예제 #24
0
 public function delete()
 {
     if (!IS_AJAX) {
         E('异常操作');
     }
     $id = I('id', 0, 'intval');
     $cate = M('cate')->select();
     import('Common/Org/Util/Data');
     $Cate = new \Data();
     $son = $Cate::hasChild($cate, $id);
     if ($son) {
         $this->error("有子分类,不能被删除,请先删除子分类");
     } else {
         //删除栏目
         if (M('cate')->delete($id)) {
             //删除栏目下的文章
             if (D('ArticleRelation')->delArticlesId($id)) {
                 echo 'true';
                 die;
             } else {
                 echo 'false';
             }
         }
     }
 }
예제 #25
0
 public function check()
 {
     if (!$this->config['business']) {
         E("贝宝设置有误!");
     }
     return true;
 }
예제 #26
0
파일: MyCache.php 프로젝트: gtyd/jira
 /**
  * 检查某个key规则是否存在
  * @param mixed $key 为字符串all时,返回规则数组;为数组时,校验key是否在规则数组中
  * @return mixed|boolean
  */
 public function findKeyRule($key = 'all')
 {
     if (is_array($key)) {
         $key = array_shift($key);
     }
     if (!is_string($key)) {
         throw E('缓存规则必须为字符串:' . json_encode($key));
     }
     $key_rules = $this->getValue(self::KEY_RULE_KEY);
     //         \Yii::warning(gettype($key_rules).":".serialize($key_rules),__CLASS__);
     if ($this->serializer === null && !is_array($key_rules) && $key_rules) {
         $key_rules = unserialize($key_rules);
     } else {
         if (!is_array($key_rules) && $key_rules) {
             $key_rules = call_user_func($this->serializer[1], $key_rules);
         }
     }
     if (!$key_rules) {
         $key_rules = $this->SetCacheKeyRule();
     }
     //         //出现直接从cache中获取某个值的时候,返回一个没有unserialize的值
     //         if(!is_array($key_rules)) {
     //             $key_rules = unserialize($key_rules);
     //         }
     if ($key == 'all') {
         return $key_rules;
     } else {
         if (!in_array($key, $key_rules)) {
             throw E("缓存规则{$key}未注册!", '100022');
         } else {
             return true;
         }
     }
 }
 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'])) {
             // 缓存有效
             //载入模版缓存文件
             Storage::load(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), $_data['var'], 'tpl');
         } else {
             $tpl = Think::instance('Think\\Template');
             // 编译并加载模板文件
             $tpl->fetch($_content, $_data['var'], $_data['prefix']);
         }
     } else {
         // 调用第三方模板引擎解析和输出
         if (strpos($engine, '\\')) {
             $class = $engine;
         } else {
             $class = 'Think\\Template\\Driver\\' . ucwords($engine);
         }
         if (class_exists($class)) {
             $tpl = new $class();
             $tpl->fetch($_content, $_data['var']);
         } else {
             // 类没有定义
             E(L('_NOT_SUPPORT_') . ': ' . $class);
         }
     }
 }
예제 #28
0
 public function initConfig()
 {
     require_cache(MODULE_PATH . "Conf/uc.php");
     if (!defined('UC_API')) {
         E('未发现uc配置文件,请确定配置文件位于' . MODULE_PATH . "Conf/uc.php");
     }
 }
예제 #29
0
 /**
  * 连接数据库方法
  * @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'],131072);
         }else{
             $this->linkID[$linkNum] = mysql_connect( $host, $config['username'], $config['password'],true,131072);
         }
         if ( !$this->linkID[$linkNum] || (!empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) ) {
             E(mysql_error());
         }
         $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         //使用UTF8存取数据库
         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];
 }
예제 #30
0
 /**
  * @throws DBException
  * @return Resource
  */
 public function connect()
 {
     if ($this->link != null) {
         return true;
     }
     $_config = $this->config;
     $_dsn = "{$_config['db_type']}:host={$_config['db_host']};port={$_config['db_port']};dbname={$_config['db_name']}";
     try {
         $this->link = new PDO($_dsn, $_config['db_user'], $_config['db_pass'], array(PDO::ATTR_PERSISTENT => false));
         $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         //设置数据库编码,默认使用UTF8编码
         $_charset = $_config['db_charset'];
         if (!$_charset) {
             $_charset = 'UTF8';
         }
         $this->link->query("SET names {$_charset}");
         $this->link->query("SET character_set_client = {$_charset}");
         $this->link->query("SET character_set_results = {$_charset}");
     } catch (PDOException $e) {
         if (APP_DEBUG) {
             E("数据库连接失败" . $e->getMessage());
         }
     }
     return $this->link;
 }