本文整理汇总了PHP中think\Db类的典型用法代码示例。如果您正苦于以下问题:PHP Db类的具体用法?PHP Db怎么用?PHP Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Db类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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, "请指定要优化的表!");
}
}
示例2: 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;
}
示例3: 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');
}
}
示例4: __construct
/**
* 架构函数
* @param array $options 缓存参数
* @access public
*/
public function __construct($options = [])
{
if (!empty($options)) {
$this->options = array_merge($this->options, $options);
}
$this->handler = \Think\Db::instance();
}
示例5: logs
/**
* 记录用户日志
* @param string $logs 用户日志
* @param array $data 操作的数据
* @param boolean $autoUid 自动获取用户UID 否则传入UID
*/
function logs($logs, $data = [], $autoUid = true)
{
$uid = $autoUid === true ? UID : $autoUid;
$data = !empty($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : '';
$data = ['uid' => $uid, 'logs' => $logs, 'datas' => $data, 'create_time' => NOW_TIME];
Db::name('Logs')->insert($data);
}
示例6: __construct
/**
* 架构函数
* @param array $options 缓存参数
* @access public
*/
public function __construct($options = [])
{
if (!empty($options)) {
$this->options = array_merge($this->options, $options);
}
$this->handler = \think\Db::connect(!empty($this->options['hostname']) || !empty($this->options['dsn']) ? $this->options : []);
}
示例7: checkExtends
/**
* 检测继承分类是否是相同的模型
* @param [type] $value [description]
* @param [type] $rule [description]
* @param [type] $data [description]
* @return [type] [description]
*/
protected function checkExtends($value, $rule, $data)
{
if (0 != $data['pid']) {
return $value == Db::name('Category')->where('id', $data['pid'])->value('model');
} else {
return true;
}
}
示例8: 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();
}
示例9: checkNode
/**
* 验证菜单是几级节点
* @param [type] $value [description]
* @param [type] $rule [description]
* @param [type] $data [description]
* @return [type] [description]
*/
protected function checkNode($pid, $rule, $data)
{
// 一级菜单最多三个
if ($pid == 0) {
return Db::name('WechatMenu')->where('pid', 0)->count() >= 3 ? '一级菜单数量最多三个' : true;
} else {
return Db::name('WechatMenu')->where('pid', $pid)->count() >= 5 ? '二级菜单数量最多五个' : true;
}
}
示例10: autoLogin
/**
* 保存登陆信息
* @param [type] $user
*/
private function autoLogin($user)
{
$loginData = ['uid' => $user['id'], 'account' => $user['account'], 'login' => $user['login'], 'last_time' => $user['last_time'], 'last_ip' => $user['last_ip']];
session('user_auth', $loginData);
session('user_auth_sign', data_auth_sign($loginData));
// 保存登陆信息
$saveData = ['last_ip' => get_client_ip(), 'last_time' => NOW_TIME, 'login' => ['exp', '`login`+1']];
Db::name('Member')->where('id', $user['id'])->update($saveData);
logs('登陆成功', '', $user['id']);
}
示例11: __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();
}
示例12: treeSelect
/**
* 返回树形选择
* @param string 分类模型
* @param integer $unShowId 排除显示的节点
* @return array
*/
public function treeSelect($model = '', $unShowId = 0)
{
$map['status'] = 1;
if ($unShowId) {
$map['id'] = ['neq', $unShowId];
}
if ($model) {
$map['model'] = $model;
}
$categorys = Db::name('category')->where($map)->order('sort asc')->select();
return Tree::toFormatTree($categorys);
}
示例13: index
/**
* 上传文件管理
*/
public function index($type = '')
{
$total = disk_total_space(".");
$this->assign('disk_use', round(($total - disk_free_space(".")) / $total * 100, 2));
$map = [];
if ($type) {
$map['type'] = $type;
}
$list = parent::_list('Storage', $map);
$this->assign('list', $list);
$this->assign('size', Db::name('Storage')->where($map)->sum('size'));
$this->assign('types', Db::name('Storage')->field('type')->distinct('type')->select());
return $this->fetch();
}
示例14: getMenuIds
/**
* 获取用户菜单节点Id集合
* @param [type] $uid 用户UID
* @return array
*/
public static function getMenuIds($uid)
{
$gIds = self::getGroupIds($uid);
$menuIds = '';
if ($gIds) {
$menuIds = Db::name('Auth')->where('id', 'in', $gIds)->column('rules');
$menuIds = implode($menuIds, ',');
$menuIds = trim($menuIds, ',');
}
$openMap = ['status' => 2, 'auth' => 0];
$openMenus = Db::name('Menu')->where($openMap)->column('id');
$openMenus = implode($openMenus, ',');
if (!empty($openMenus)) {
$menuIds .= ',' . $openMenus;
}
return trim($menuIds, ',');
}
示例15: password
/**
* 修改密码
*/
public function password()
{
if (IS_POST) {
$data = $this->request->post();
$validate = Loader::validate('Member');
if (!$validate->scene('changepass')->check($data)) {
return $this->error($validate->getError());
}
$passData = ['password' => umd5($data['newpass']), 'update_time' => NOW_TIME];
if (Db::name('Member')->where('id', UID)->update($passData)) {
return $this->success('密码修改成功');
} else {
return $this->error();
}
} else {
return $this->fetch();
}
}