<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 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\App;
use think\Cache;
use think\Collection;
use think\Config;
use think\Db;
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\model\relation\OneToOne;
use think\Paginator;
class Query
{
// 数据库Connection对象实例
protected $connection;
// 数据库Builder对象实例
protected $builder;
// 当前模型类名称
protected $model;
// 当前数据表名称(含前缀)
protected $table = '';
// 当前数据表名称(不含前缀)
protected $name = '';
// 当前数据表主键
protected $pk;
// 当前数据表前缀
protected $prefix = '';
// 查询参数
protected $options = [];
// 参数绑定
protected $bind = [];
// 数据表信息
protected static $info = [];
// 回调事件
private static $event = [];
/**
* 构造函数
* @access public
* @param Connection $connection 数据库对象实例
* @param string $model 模型名
*/
public function __construct(Connection $connection = null, $model = '')
{
$this->connection = $connection ?: Db::connect([], true);
$this->prefix = $this->connection->getConfig('prefix');
$this->model = $model;
// 设置当前连接的Builder对象
$this->setBuilder();
}
/**
* 利用__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);
$this->setBuilder();
$this->prefix = $this->connection->getConfig('prefix');
return $this;
}
/**
* 设置当前的数据库Builder对象
* @access protected
* @return void
*/
protected function setBuilder()
{
$class = $this->connection->getBuilder();
$this->builder = new $class($this->connection, $this);
}
/**
* 获取当前的模型对象名
* @access public
* @return string
*/
public function getModel()
{
return $this->model;
}
/**
* 获取当前的builder实例对象
* @access public
* @return Builder
*/
public function getBuilder()
{
return $this->builder;
}
/**
* 指定默认的数据表名(不含前缀)
* @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->rollb
没有合适的资源?快使用搜索试试~ 我知道了~
ajax_分页Thinkphp5_jquery_php
共938个文件
php:281个
png:232个
jpg:118个
1星 需积分: 9 12 下载量 131 浏览量
2018-02-28
15:07:47
上传
评论
收藏 14.26MB ZIP 举报
温馨提示
只求分享, 分页,ajax,Thinkphp5,jquery,php, 采用最新TP5多层开发, ajax jquery 无刷新分页效果,并带图, 带数据库, 简单易用,本人新手开发,恳请多多关照!!谢谢,祝贺 2018大家一起发财!!!
资源推荐
资源详情
资源评论
收起资源包目录
ajax_分页Thinkphp5_jquery_php (938个子文件)
test.bmp 0B
style.css 97KB
style.css 97KB
bootstrap.min.css 71KB
bootstrap.min.css 71KB
base.css 54KB
base.css 54KB
base.css 54KB
bak.css 48KB
bak.css 48KB
bak.css 48KB
page1.css 17KB
page1.css 17KB
css.css 12KB
css.css 12KB
base.css 11KB
base.css 11KB
tips.css 7KB
css_tips.2.0.css 7KB
tips.2.0.css 7KB
gray.css 7KB
red.css 7KB
green.css 7KB
jedate.css 7KB
font-icons.css 5KB
font-icons.css 5KB
public.css 4KB
share_style0_16.css 4KB
share_style0_16.css 4KB
public.css 4KB
jquery.css 4KB
jquery.css 4KB
jquery.bxslider.css 4KB
flexslider.css 4KB
flexslider.css 4KB
flexslider.css 4KB
reset.css 3KB
reset.css 3KB
reset.css 3KB
component.css 2KB
component.css 2KB
page.css 2KB
page.css 2KB
manhuaDate.1.0.css 2KB
manhuaDate.1.0.css 2KB
tcdPageCode.css 2KB
hack.css 866B
hack.css 866B
reset.css 669B
reset.css 669B
print.css 153B
print.css 143B
haiersoft.css 103B
haiersoft.css 91B
formdata.css 23B
Migration.template.php.dist 756B
Seed.template.php.dist 326B
ui-icons.eot 35KB
ui-icons.eot 35KB
hiddeninput.exe 9KB
test.gif 233KB
bg017.gif 976B
.gitignore 43B
.gitignore 42B
.gitignore 39B
.gitignore 29B
.gitignore 29B
.gitignore 28B
.gitignore 16B
.gitignore 13B
.gitignore 13B
.gitignore 13B
.gitignore 13B
.gitignore 7B
.htaccess 216B
.htaccess 13B
.htaccess 13B
index.html 108KB
index.html 108KB
single-post.html 64KB
aboutrt.html 12KB
history.html 11KB
index.html 9KB
footer.html 8KB
society_edit.html 6KB
left.html 6KB
society_add.html 6KB
research.html 6KB
main.html 6KB
society.html 6KB
main.html 6KB
society.html 5KB
left.html 5KB
head.html 5KB
campus.html 5KB
p1.html 4KB
p1.html 4KB
footer.html 4KB
tab.html 4KB
tab.html 4KB
共 938 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
- numtv2019-12-05根本运行不了的垃圾代码!骗分的!
13339923966
- 粉丝: 13
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功