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


PHP Db::getInstance方法代碼示例

本文整理匯總了PHP中think\Db::getInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Db::getInstance方法的具體用法?PHP Db::getInstance怎麽用?PHP Db::getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在think\Db的用法示例。


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

示例1: uninstall

 public function uninstall()
 {
     $db_config = array();
     $db_config['DB_TYPE'] = C('DB_TYPE');
     $db_config['DB_HOST'] = C('DB_HOST');
     $db_config['DB_NAME'] = C('DB_NAME');
     $db_config['DB_USER'] = C('DB_USER');
     $db_config['DB_PWD'] = C('DB_PWD');
     $db_config['DB_PORT'] = C('DB_PORT');
     $db_config['DB_PREFIX'] = C('DB_PREFIX');
     $db = Db::getInstance($db_config);
     //讀取插件sql文件
     $sqldata = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Addons/' . $this->info['name'] . '/uninstall.sql');
     $sqlFormat = $this->sql_split($sqldata, $db_config['DB_PREFIX']);
     $counts = count($sqlFormat);
     for ($i = 0; $i < $counts; $i++) {
         $sql = trim($sqlFormat[$i]);
         $db->execute($sql);
         //執行語句
     }
     //刪除鉤子
     $Hooks = M("Hooks");
     $map['name'] = array('in', 'DisplayFocus');
     $res = $Hooks->where($map)->delete();
     if ($res == false) {
         session('addons_install_error', $Hooks->getError());
         return false;
     }
     return true;
 }
開發者ID:slpi1,項目名稱:onethinkTemplate,代碼行數:30,代碼來源:FocusAddon.class.php

示例2: step3

 public function step3()
 {
     if (session('step') != 2) {
         $this->redirect('step2');
     }
     $this->display();
     //連接數據庫
     $dbconfig = session('db_config');
     $db = Db::getInstance($dbconfig);
     //創建數據表
     create_tables($db, $dbconfig['DB_PREFIX']);
     //注冊創始人帳號
     $auth = build_auth_key();
     $admin = session('admin_info');
     register_administrator($db, $dbconfig['DB_PREFIX'], $admin, $auth);
     //創建配置文件
     $conf = write_config($dbconfig, $auth);
     session('config_file', $conf);
     if (session('error')) {
         //show_msg();
     } else {
         session('step', 3);
         $this->redirect('Index/complete');
     }
 }
開發者ID:GuiFox,項目名稱:Morplee,代碼行數:25,代碼來源:InstallController.class.php

示例3: optimize

 /**
  * 優化表
  */
 public function optimize()
 {
     $tables = $_REQUEST['tables'];
     if ($tables) {
         $Db = Db::getInstance();
         if (is_array($tables)) {
             $tables = implode('`,`', $tables);
             $list = $Db->query("OPTIMIZE TABLE `{$tables}`");
             if ($list) {
                 $this->ajaxReturn(1, "數據表優化完成!");
             } else {
                 $this->ajaxReturn(0, "數據表優化出錯請重試!");
             }
         } else {
             $list = $Db->query("OPTIMIZE TABLE `{$tables}`");
             $tables_ts = substr($tables, 3);
             if ($list) {
                 $this->ajaxReturn(1, "數據表'{$tables_ts}'優化完成!");
             } else {
                 $this->ajaxReturn(0, "數據表'{$tables_ts}'優化出錯請重試!");
             }
         }
     } else {
         $this->ajaxReturn(0, "請指定要優化的表!");
     }
 }
開發者ID:noikiy,項目名稱:wakeup,代碼行數:29,代碼來源:ToolController.class.php

示例4: index

 public function index()
 {
     $Db = Db::getInstance();
     $list = $Db->query('SHOW TABLE STATUS');
     $list = array_map('array_change_key_case', $list);
     $this->assign('list', $list);
     $this->display();
 }
開發者ID:php-wechat,項目名稱:wechat,代碼行數:8,代碼來源:DataBackController.class.php

示例5: __construct

 /**
  * 架構函數
  * @param array $options 緩存參數
  * @access public
  */
 public function __construct($options = array())
 {
     if (empty($options)) {
         $options = array('table' => C('DATA_CACHE_TABLE'));
     }
     $this->options = $options;
     $this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : C('DATA_CACHE_PREFIX');
     $this->options['length'] = isset($options['length']) ? $options['length'] : 0;
     $this->options['expire'] = isset($options['expire']) ? $options['expire'] : C('DATA_CACHE_TIME');
     $this->handler = \Think\Db::getInstance();
 }
開發者ID:novnan,項目名稱:meiju,代碼行數:16,代碼來源:Db.class.php

示例6: getSql

 private function getSql($name)
 {
     $db_config = array();
     $db_config['DB_TYPE'] = C('DB_TYPE');
     $db_config['DB_HOST'] = C('DB_HOST');
     $db_config['DB_NAME'] = C('DB_NAME');
     $db_config['DB_USER'] = C('DB_USER');
     $db_config['DB_PWD'] = C('DB_PWD');
     $db_config['DB_PORT'] = C('DB_PORT');
     $db_config['DB_PREFIX'] = C('DB_PREFIX');
     $this->db = Db::getInstance($db_config);
     //讀取插件sql文件
     $sqldata = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Addons/' . $this->info['name'] . '/' . $name . '.sql');
     $sqlFormat = $this->sql_split($sqldata, $db_config['DB_PREFIX']);
     foreach ($sqlFormat as $key => $value) {
         # code...
     }
     return $sqlFormat;
 }
開發者ID:00606,項目名稱:cmge,代碼行數:19,代碼來源:BgDesignAddon.class.php

示例7: uninstall

 public function uninstall()
 {
     $db_config = array();
     $db_config['DB_TYPE'] = C('DB_TYPE');
     $db_config['DB_HOST'] = C('DB_HOST');
     $db_config['DB_NAME'] = C('DB_NAME');
     $db_config['DB_USER'] = C('DB_USER');
     $db_config['DB_PWD'] = C('DB_PWD');
     $db_config['DB_PORT'] = C('DB_PORT');
     $db_config['DB_PREFIX'] = C('DB_PREFIX');
     $db = Db::getInstance($db_config);
     //讀取插件sql文件
     $sqldata = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Addons/' . $this->info['name'] . '/uninstall.sql');
     $sqlFormat = $this->sql_split($sqldata, $db_config['DB_PREFIX']);
     $counts = count($sqlFormat);
     for ($i = 0; $i < $counts; $i++) {
         $sql = trim($sqlFormat[$i]);
         $db->execute($sql);
         //執行語句
     }
     return true;
 }
開發者ID:naliduo,項目名稱:Lightweight-social-platform,代碼行數:22,代碼來源:SuperLinksAddon.class.php

示例8: repair

 /**
  * 修複表
  * @param  String $tables 表名
  * @author 麥當苗兒 <zuojiazi@vip.qq.com>
  */
 public function repair($tables = null)
 {
     if ($tables) {
         $Db = Db::getInstance();
         if (is_array($tables)) {
             $tables = implode('`,`', $tables);
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->success("數據表修複完成!");
             } else {
                 $this->error("數據表修複出錯請重試!");
             }
         } else {
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->mtReturn(201, "數據表'{$tables}'修複完成!", '', 'forward', U('index'));
             } else {
                 $this->mtReturn(300, "數據表'{$tables}'修複出錯請重試!");
             }
         }
     } else {
         $this->error("請指定要修複的表!");
     }
 }
開發者ID:Willshon,項目名稱:OLCS,代碼行數:29,代碼來源:DatabaseController.class.php

示例9: step4

    public function step4()
    {
        if (session('step') !== '3') {
            $this->error('請按順序安裝', U('step3'));
        }
        session('step', '4');
        session('error', false);
        $this->assign('meta_title', "step4");
        $this->display();
        //連接數據庫
        $db_config = session('db_config');
        $db_instance = Db::getInstance($db_config);
        //創建數據表
        create_tables($db_instance, $db_config['DB_PREFIX']);
        //生成加密字符串
        $add_chars .= '`~!@#$%^&*()_+-=[]{};:"|,.<>/?';
        $auth = String::randString(64, '', $add_chars);
        //生成隨機數
        //創建配置文件
        $conf = write_config($db_config, $auth);
        //根據加密字符串更新admin密碼的加密結果
        $new_admin_password = user_md5('admin', $auth);
        $sql = <<<SQL
        UPDATE `{$db_config["DB_PREFIX"]}admin_config` SET `value`='{$auth}' WHERE `name` = 'AUTH_KEY';
        UPDATE `{$db_config["DB_PREFIX"]}admin_user` SET `password`='{$new_admin_password}' WHERE `id` = 1;
SQL;
        $result = $db_instance->execute($sql);
        if (!$result) {
            $this->error('寫入係統加密KEY或管理員新密碼出錯!');
        }
        if (session('error')) {
            $this->error('安裝出錯', 'index');
        } else {
            $this->redirect('complete');
        }
    }
開發者ID:lipeng-github,項目名稱:corethink,代碼行數:36,代碼來源:IndexController.class.php

示例10: repair

 /**
  * 修複表
  * @param  String $tables 表名
  * @author 麥當苗兒 <zuojiazi@vip.qq.com>
  */
 public function repair($tables = null)
 {
     if ($tables) {
         $Db = Db::getInstance();
         if (is_array($tables)) {
             $tables = implode('`,`', $tables);
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->success(L('_REPAIR_COMPLETE_PARAM_', array('name' => '')) . L('_EXCLAMATION_'));
             } else {
                 $this->error(L('_REPAIR_ERROR_PARAM_', array('name' => '')) . L('_EXCLAMATION_'));
             }
         } else {
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->success(L('_REPAIR_COMPLETE_PARAM_', array('name' => $tables)) . L('_EXCLAMATION_'));
             } else {
                 $this->error(L('_REPAIR_ERROR_PARAM_', array('name' => $tables)) . L('_EXCLAMATION_'));
             }
         }
     } else {
         $this->error(L('_REPAIR_ASSIGN_') . L('_EXCLAMATION_'));
     }
 }
開發者ID:nanhuacrab,項目名稱:jhysns,代碼行數:29,代碼來源:DatabaseController.class.php

示例11: clear

 public function clear()
 {
     $Db = Db::getInstance();
     $tables = array("wst_users_member", "wst_users_member_apply", "wst_users_member_relation", "wst_users_member_voucher_earn");
     if (IS_POST) {
         $rd = array('status' => -1);
         foreach ($tables as $k => $v) {
             $Db->query("TRUNCATE TABLE {$v}");
         }
         $Db->query("update wst_users_member set b_left_user_id=0, b_middle_user_id=0,b_right_user_id=0,parentId=0,recommendId=0,reaches=0,level=0");
         $rd = array('status' => 1);
         $this->ajaxReturn($rd);
     } else {
         $this->display("/clear");
     }
 }
開發者ID:shadows05,項目名稱:mall,代碼行數:16,代碼來源:IndexAction.class.php

示例12: repair

 /**
  * 修複表
  * @param  String $tables 表名
  * @author 麥當苗兒 <zuojiazi@vip.qq.com>
  */
 public function repair($tables = null)
 {
     if ($tables) {
         $Db = Db::getInstance();
         if (is_array($tables)) {
             $tables = implode('`,`', $tables);
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->mtReturn(200, "數據表修複完成!", $_REQUEST['navTabId'], false);
             } else {
                 $this->mtReturn(300, "數據表修複出錯請重試!", $_REQUEST['navTabId'], false);
             }
         } else {
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->mtReturn(200, "數據表'{$tables}'修複完成!", $_REQUEST['navTabId'], false);
             } else {
                 $this->mtReturn(300, "數據表'{$tables}'修複出錯請重試!", $_REQUEST['navTabId'], false);
             }
         }
     } else {
         $this->error("請指定要修複的表!");
     }
 }
開發者ID:siimanager,項目名稱:sii,代碼行數:29,代碼來源:DatabaseController.class.php

示例13: step3

 public function step3()
 {
     $data = session('install_config');
     if (!$data) {
         $this->error('非法訪問');
     }
     $field = array('DB_TYPE', 'DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PWD', 'DB_PORT', 'DB_PREFIX');
     $database = array();
     foreach ($field as $key) {
         $database[$key] = $data[$key];
     }
     $db = Db::getInstance($database);
     //sql字段替換
     $sql = file_get_contents(MODULE_PATH . 'Data/sql.sql');
     $sql = str_replace('[[DB_PREFIX]]', $data['DB_PREFIX'], $sql);
     //將sql文件解析成單條語句
     $ret = sql_split($sql);
     //創建管理員賬號
     $passwordInfo = password($data['password']);
     $password = $passwordInfo['password'];
     $encrypt = $passwordInfo['encrypt'];
     $email = trim($data['email']);
     array_push($ret, "update {$data['DB_PREFIX']}admin set `username`='{$data['username']}',`password`='{$password}',`roleid`='1',`encrypt`='{$encrypt}',`email`='{$email}' where `userid`='1'");
     $tip = array();
     //執行情況統計
     //安裝進度顯示
     array_push($tip, array('開始安裝數據庫', ''));
     foreach ($ret as $value) {
         $value = trim($value);
         if (empty($value)) {
             continue;
         }
         if (substr($value, 0, 12) == 'CREATE TABLE') {
             $name = preg_replace("/^CREATE TABLE `(\\w+)`.*/is", "\\1", $value);
             $msg = "創建數據表{$name}";
             if (false !== $db->execute($value)) {
                 array_push($tip, array($msg, '成功'));
             } else {
                 array_push($tip, array($msg, '失敗'));
             }
         } elseif (substr($value, 0, 11) == 'INSERT INTO') {
             $name = preg_replace("/^INSERT INTO `(\\w+)`.*/is", "\\1", $value);
             $msg = "寫入數據到{$name}";
             if (false !== $db->execute($value)) {
                 array_push($tip, array($msg, '成功'));
             } else {
                 array_push($tip, array($msg, '失敗'));
             }
         } else {
             $db->execute($value);
         }
     }
     //同步配置文件
     if (APP_MODE != 'sae') {
         $configFile = CONF_PATH . 'config.php';
         $data = file_get_contents($configFile);
         $data = preg_replace("/('DB_TYPE'\\s*=>\\s*)'(.*)',/Us", "\\1'{$database['DB_TYPE']}',", $data);
         $data = preg_replace("/('DB_HOST'\\s*=>\\s*)'(.*)',/Us", "\\1'{$database['DB_HOST']}',", $data);
         $data = preg_replace("/('DB_NAME'\\s*=>\\s*)'(.*)',/Us", "\\1'{$database['DB_NAME']}',", $data);
         $data = preg_replace("/('DB_USER'\\s*=>\\s*)'(.*)',/Us", "\\1'{$database['DB_USER']}',", $data);
         $data = preg_replace("/('DB_PWD'\\s*=>\\s*)'(.*)',/Us", "\\1'{$database['DB_PWD']}',", $data);
         $data = preg_replace("/('DB_PORT'\\s*=>\\s*)'(.*)',/Us", "\\1'{$database['DB_PORT']}',", $data);
         $data = preg_replace("/('DB_PREFIX'\\s*=>\\s*)'(.*)',/Us", "\\1'{$database['DB_PREFIX']}',", $data);
         $data = preg_replace("/('report'\\s*=>\\s*)'(.*)',/Us", "\\1'{$email}',", $data);
         file_put_contents($configFile, $data);
         array_push($tip, array('寫入配置文件', '成功'));
     }
     session('install_step', 4);
     array_push($tip, array('安裝完成', ''));
     $this->assign('tip', $tip);
     $this->display();
 }
開發者ID:easytp,項目名稱:easytp,代碼行數:72,代碼來源:IndexController.class.php

示例14: backup_table

 /**
  * @param int $type 備份類型,1:table,2:row,3:all
  */
 private function backup_table($table, $type = 1, $start = 0)
 {
     $db = Db::getInstance();
     switch ($type) {
         case 1:
             if (0 == $start) {
                 $result = $db->query("SHOW CREATE TABLE `{$table}`");
                 $sql = "\n";
                 $sql .= "-- -----------------------------\n";
                 $sql .= "-- 表結構 `{$table}`\n";
                 $sql .= "-- -----------------------------\n";
                 //$sql .= "DROP TABLE IF EXISTS `{$table}`;\n";
                 $sql .= str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', trim($result[0]['Create Table']) . ";\n\n");
                 if (false === $this->write($sql)) {
                     return false;
                 }
             }
             //數據總數
             $result = $db->query("SELECT COUNT(*) AS count FROM `{$table}`");
             $count = $result['0']['count'];
             break;
         case 2:
             //寫入數據注釋
             if (0 == $start) {
                 $sql = "-- -----------------------------\n";
                 $sql .= "-- 表內記錄 `{$table}`\n";
                 $sql .= "-- -----------------------------\n";
                 $this->write($sql);
             }
             //備份數據記錄
             $result = $db->query("SELECT * FROM `{$table}` LIMIT {$start}, 1000");
             foreach ($result as $row) {
                 $row = array_map('addslashes', $row);
                 $sql = "INSERT INTO `{$table}` VALUES ('" . str_replace(array("\r", "\n"), array('\\r', '\\n'), implode("', '", $row)) . "');\n";
                 if (false === $this->write($sql)) {
                     return false;
                 }
             }
             break;
         case 3:
             if (0 == $start) {
                 $result = $db->query("SHOW CREATE TABLE `{$table}`");
                 $sql = "\n";
                 $sql .= "-- -----------------------------\n";
                 $sql .= "-- Table structure for `{$table}`\n";
                 $sql .= "-- -----------------------------\n";
                 $sql .= "DROP TABLE IF EXISTS `{$table}`;\n";
                 $sql .= trim($result[0]['Create Table']) . ";\n\n";
                 if (false === $this->write($sql)) {
                     return false;
                 }
             }
             //數據總數
             $result = $db->query("SELECT COUNT(*) AS count FROM `{$table}`");
             $count = $result['0']['count'];
             //備份表數據
             if ($count) {
                 //寫入數據注釋
                 if (0 == $start) {
                     $sql = "-- -----------------------------\n";
                     $sql .= "-- Records of `{$table}`\n";
                     $sql .= "-- -----------------------------\n";
                     $this->write($sql);
                 }
                 //備份數據記錄
                 $result = $db->query("SELECT * FROM `{$table}` LIMIT {$start}, 1000");
                 foreach ($result as $row) {
                     $row = array_map('addslashes', $row);
                     $sql = "INSERT INTO `{$table}` VALUES ('" . str_replace(array("\r", "\n"), array('\\r', '\\n'), implode("', '", $row)) . "');\n";
                     if (false === $this->write($sql)) {
                         return false;
                     }
                 }
                 //還有更多數據
                 if ($count > $start + 1000) {
                     return array($start + 1000, $count);
                 }
             }
             break;
     }
 }
開發者ID:tmac1997,項目名稱:DormitoryWebsite,代碼行數:84,代碼來源:DevtoolController.class.php

示例15: step3

 public function step3()
 {
     /* if(session('step') != 2){
            $this->redirect('step2');
        }*/
     $this->display();
     //連接數據庫
     $dbconfig = cookie('db_config');
     $db = Db::getInstance($dbconfig);
     //創建數據表
     create_tables($db, $dbconfig['DB_PREFIX']);
     //注冊創始人帳號
     $auth = build_auth_key();
     $admin = session('admin_info');
     register_administrator($db, $dbconfig['DB_PREFIX'], $admin, $auth);
     //創建配置文件
     $conf = write_config($dbconfig, $auth);
     session('config_file', $conf);
     if (session('error')) {
         //show_msg();
     } else {
         session('step', 3);
         echo "<script type=\"text/javascript\">setTimeout(function(){location.href='" . U('Index/complete') . "'},5000)</script>";
         ob_flush();
         flush();
         //$this->redirect('Index/complete');
     }
 }
開發者ID:terrydeng,項目名稱:beimeibang1205,代碼行數:28,代碼來源:InstallController.class.php


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