<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\db;
use PDO;
use think\Cache;
use think\Collection;
use think\Config;
use think\Db;
use think\db\Builder;
use think\db\Connection;
use think\db\exception\BindParamException;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\Loader;
use think\Model;
use think\model\Relation;
use think\Paginator;
class Query
{
// 数据库Connection对象实例
protected $connection;
// 数据库驱动类型
protected $builder;
// 当前模型类名称
protected $model;
// 当前数据表名称(含前缀)
protected $table = '';
// 当前数据表名称(不含前缀)
protected $name = '';
// 当前数据表主键
protected $pk;
// 当前数据表前缀
protected $prefix = '';
// 查询参数
protected $options = [];
// 参数绑定
protected $bind = [];
// 数据表信息
protected static $info = [];
/**
* 架构函数
* @access public
* @param Connection $connection 数据库对象实例
* @param string $model 模型名
*/
public function __construct(Connection $connection = null, $model = '')
{
$this->connection = $connection ?: Db::connect([], true);
$this->builder = $this->connection->getConfig('builder') ?: $this->connection->getConfig('type');
$this->prefix = $this->connection->getConfig('prefix');
$this->model = $model;
}
/**
* 利用__call方法实现一些特殊的Model方法
* @access public
* @param string $method 方法名称
* @param array $args 调用参数
* @return mixed
* @throws DbException
* @throws Exception
*/
public function __call($method, $args)
{
if (strtolower(substr($method, 0, 5)) == 'getby') {
// 根据某个字段获取记录
$field = Loader::parseName(substr($method, 5));
$where[$field] = $args[0];
return $this->where($where)->find();
} elseif (strtolower(substr($method, 0, 10)) == 'getfieldby') {
// 根据某个字段获取记录的某个值
$name = Loader::parseName(substr($method, 10));
$where[$name] = $args[0];
return $this->where($where)->value($args[1]);
} else {
throw new Exception('method not exist:' . __CLASS__ . '->' . $method);
}
}
/**
* 获取当前的数据库Connection对象
* @access public
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* 切换当前的数据库连接
* @access public
* @param mixed $config
* @return $this
*/
public function connect($config)
{
$this->connection = Db::connect($config);
return $this;
}
/**
* 指定默认的数据表名(不含前缀)
* @access public
* @param string $name
* @return $this
*/
public function name($name)
{
$this->name = $name;
return $this;
}
/**
* 指定默认数据表名(含前缀)
* @access public
* @param string $table 表名
* @return $this
*/
public function setTable($table)
{
$this->table = $table;
return $this;
}
/**
* 得到当前或者指定名称的数据表
* @access public
* @param string $name
* @return string
*/
public function getTable($name = '')
{
if ($name || empty($this->table)) {
$name = $name ?: $this->name;
$tableName = $this->prefix;
if ($name) {
$tableName .= Loader::parseName($name);
}
} else {
$tableName = $this->table;
}
return $tableName;
}
/**
* 将SQL语句中的__TABLE_NAME__字符串替换成带前缀的表名(小写)
* @access public
* @param string $sql sql语句
* @return string
*/
public function parseSqlTable($sql)
{
if (false !== strpos($sql, '__')) {
$prefix = $this->prefix;
$sql = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function ($match) use ($prefix) {
return $prefix . strtolower($match[1]);
}, $sql);
}
return $sql;
}
/**
* 执行查询 返回数据集
* @access public
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param boolean $master 是否在主服务器读操作
* @param bool|string $class 指定返回的数据集对象
* @return mixed
* @throws BindParamException
* @throws PDOException
*/
public function query($sql, $bind = [], $master = false, $class = false)
{
return $this->connection->query($sql, $bind, $master, $class);
}
/**
* 执行语句
* @access public
* @param string $sql sql指令
* @param array $bind 参数绑定
* @return int
* @throws BindParamException
* @throws PDOException
*/
public function execute($sql, $bind = [])
{
return $this->connection->execute($sql, $bind);
}
/**
* 获取最近插入的ID
* @access public
* @param string $sequence 自增序列名
* @return string
*/
public function getLastInsID($sequence = null)
{
return $this->connection->getLastInsID($sequence);
}
/**
* 获取最近一次查询的sql语句
* @access public
* @return string
*/
public function getLastSql()
{
return $this->connection->getLastSql();
}
/**
* 执行数据库事务
* @access public
* @param callable $callback 数据操作方法回调
* @return mixed
*/
public function transaction($callback)
{
return $this->connection->transaction($callback);
}
/**
* 启动事务
* @access public
* @return void
*/
public function startTrans()
{
$this->connection->startTrans();
}
/**
* 用于非自动提交状态下面的查询提交
* @access public
* @return void
* @throws PDOException
*/
public function commit()
{
$this->connection->commit();
}
/**
* 事务回滚
* @access public
* @return void
* @throws PDOException
*/
public function rollback()
{
$this->connection->rollback();
}
/**
* 批处理执行SQL语句
* 批处理的指令都认为是execute操作
* @access public
* @param array $sql SQL批处理指令
* @return boolean
*/
public function batchQuery($sql = [])
{
return $this->connection->batchQuery($sql);
}
/**
* 获取数据库的配置参数
* @access public
* @param string $name 参数名称
* @return boolean
*/
public function getConfig($name = '')
{
return $this->connection->getConfig($name);
}
/**
* 得到分表的的数据表名
* @access public
* @param array $data 操作的数据
* @param string $field 分表依据的字段
* @
没有合适的资源?快使用搜索试试~ 我知道了~
thinkphp5多标签后台源码
共791个文件
js:181个
php:176个
png:143个
5星 · 超过95%的资源 需积分: 10 46 下载量 91 浏览量
2018-02-17
22:25:57
上传
评论
收藏 9.97MB ZIP 举报
温馨提示
thinkphp5框架后台模板,后台页面是多标签的,样式简洁,开发方便,适合一般CMS,CRM,ERP等后台管理
资源推荐
资源详情
资源评论
收起资源包目录
thinkphp5多标签后台源码 (791个子文件)
summernote-bs3.css 143KB
bootstrap.min.css 118KB
style.min.css 97KB
animate.min.css 46KB
ueditor.css 43KB
ueditor.min.css 34KB
datepicker3.css 33KB
font-awesome.min.css 26KB
ambiance.css 25KB
style.min.css 25KB
video-js.css 21KB
image.css 18KB
sweetalert.css 18KB
simditor.css 17KB
ui.jqgridffe4.css 16KB
video.css 15KB
attachment.css 14KB
jasny-bootstrap.min.css 14KB
chosen.css 12KB
dropzone.css 11KB
video-js.min.css 11KB
layer.css 11KB
layim.css 11KB
fullcalendar.css 11KB
summernote.css 10KB
plyr.css 10KB
zTreeStyle.css 7KB
codemirror.css 7KB
shCoreDefault.css 7KB
blueimp-gallery.min.css 7KB
awesome-bootstrap-checkbox.css 7KB
toastr.min.css 7KB
laydate.css 6KB
webuploader-demo.min.css 6KB
laydate.css 6KB
jquery.steps.css 6KB
footable.core.css 5KB
jquery.fancybox.css 5KB
dataTables.bootstrap.css 5KB
bootstrap-table.min.css 4KB
scrawl.css 4KB
clockpicker.css 4KB
basic.css 4KB
style.css 4KB
laydate.css 3KB
bootstrap-colorpicker.min.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
cropper.min.css 3KB
ion.rangeSlider.css 3KB
jquery.nouislider.css 3KB
layer.ext.css 3KB
codemirror.css 3KB
bootstrap-markdown.min.css 3KB
charts.css 3KB
jquery.gritter.css 3KB
background.css 2KB
ion.rangeSlider.skinFlat.css 2KB
emotion.css 2KB
dialogbase.css 2KB
music.css 2KB
login.min.css 1KB
custom.css 1KB
edittable.css 1KB
bootstrap-treeview.css 1KB
template.css 1KB
fullcalendar.print.css 660B
switchery.css 611B
webuploader.css 515B
webuploader.css 515B
morris-0.4.3.min.css 443B
help.css 389B
iframe.css 41B
Thumbs.db 29KB
Thumbs.db 4KB
fontawesome-webfontd41d.eot 67KB
fontawesome-webfont93e3.eot 67KB
glyphicons-halflings-regulard41d.eot 20KB
glyphicons-halflings-regular.eot 20KB
footable.eot 5KB
footabled41d.eot 5KB
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
hiddeninput.exe 9KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
fancybox_loading@2x.gif 14KB
cface.gif 8KB
fancybox_loading.gif 6KB
loading-0.gif 6KB
共 791 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
- iozzz2018-10-10不是自己想要的,有图就好了,还是谢谢了
- grass99872018-07-05可以,真心不错。
3210_0123
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功