Db.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace think;
  12. /**
  13. * Class Db
  14. * @package think
  15. * @method \think\db\Query table(string $table) static 指定数据表(含前缀)
  16. * @method \think\db\Query name(string $name) static 指定数据表(不含前缀)
  17. * @method \think\db\Query where(mixed $field, string $op = null, mixed $condition = null) static 查询条件
  18. * @method \think\db\Query join(mixed $join, mixed $condition = null, string $type = 'INNER') static JOIN查询
  19. * @method \think\db\Query view(mixed $join, mixed $field = null, mixed $on = null, string $type = 'INNER') static 视图查询
  20. * @method \think\db\Query union(mixed $union, boolean $all = false) static UNION查询
  21. * @method \think\db\Query limit(mixed $offset, integer $length = null) static 查询LIMIT
  22. * @method \think\db\Query order(mixed $field, string $order = null) static 查询ORDER
  23. * @method \think\db\Query cache(mixed $key = null , integer $expire = null) static 设置查询缓存
  24. * @method mixed value(string $field) static 获取某个字段的值
  25. * @method array column(string $field, string $key = '') static 获取某个列的值
  26. * @method mixed find(mixed $data = null) static 查询单个记录
  27. * @method mixed select(mixed $data = null) static 查询多个记录
  28. * @method integer insert(array $data, boolean $replace = false, boolean $getLastInsID = false, string $sequence = null) static 插入一条记录
  29. * @method integer insertGetId(array $data, boolean $replace = false, string $sequence = null) static 插入一条记录并返回自增ID
  30. * @method integer insertAll(array $dataSet) static 插入多条记录
  31. * @method integer update(array $data) static 更新记录
  32. * @method integer delete(mixed $data = null) static 删除记录
  33. * @method boolean chunk(integer $count, callable $callback, string $column = null) static 分块获取数据
  34. * @method \Generator cursor(mixed $data = null) static 使用游标查找记录
  35. * @method mixed query(string $sql, array $bind = [], boolean $master = false, bool $pdo = false) static SQL查询
  36. * @method integer execute(string $sql, array $bind = [], boolean $fetch = false, boolean $getLastInsID = false, string $sequence = null) static SQL执行
  37. * @method \think\Paginator paginate(integer $listRows = 15, mixed $simple = null, array $config = []) static 分页查询
  38. * @method mixed transaction(callable $callback) static 执行数据库事务
  39. * @method void startTrans() static 启动事务
  40. * @method void commit() static 用于非自动提交状态下面的查询提交
  41. * @method void rollback() static 事务回滚
  42. * @method boolean batchQuery(array $sqlArray) static 批处理执行SQL语句
  43. * @method string getLastInsID($sequence = null) static 获取最近插入的ID
  44. */
  45. class Db
  46. {
  47. /**
  48. * 查询次数
  49. * @var integer
  50. */
  51. public static $queryTimes = 0;
  52. /**
  53. * 执行次数
  54. * @var integer
  55. */
  56. public static $executeTimes = 0;
  57. public static function __callStatic($method, $args)
  58. {
  59. $class = Container::get('config')->get('database.query') ?: '\\think\\db\\Query';
  60. $query = new $class();
  61. return call_user_func_array([$query, $method], $args);
  62. }
  63. }