Properties

$instance

$instance : array

数据库连接实例

Type

array

$config

$config : array

数据库配置

Type

array

$event

$event : array|object

Event对象或者数组

Type

array|object

$listen

$listen : array

SQL监听

Type

array

$dbLog

$dbLog : array

SQL日志

Type

array

$queryTimes

$queryTimes : int

查询次数

Type

int

$cache

$cache : \Psr\SimpleCache\CacheInterface

查询缓存对象

Type

CacheInterface

$log

$log : \Psr\Log\LoggerInterface

查询日志对象

Type

LoggerInterface

Methods

__construct()

__construct() : mixed

架构函数

Returns

mixed —

setConfig()

setConfig(array  $config) : void

初始化配置参数

Parameters

array $config

连接配置

setCache()

setCache(\Psr\SimpleCache\CacheInterface  $cache) : void

设置缓存对象

Parameters

\Psr\SimpleCache\CacheInterface $cache

缓存对象

setLog()

setLog(\Psr\Log\LoggerInterface  $log) : void

设置日志对象

Parameters

\Psr\Log\LoggerInterface $log

日志对象

log()

log(string  $log, string  $type = 'sql') : void

记录SQL日志

Parameters

string $log

SQL日志信息

string $type

日志类型

getDbLog()

getDbLog(bool  $clear = false) : array

获得查询日志(没有设置日志对象使用)

Parameters

bool $clear

是否清空

Returns

array —

getConfig()

getConfig(string  $name = '', mixed  $default = null) : mixed

获取配置参数

Parameters

string $name

配置参数

mixed $default

默认值

Returns

mixed —

connect()

connect(string|null  $name = null, bool  $force = false) : \think\db\ConnectionInterface

创建/切换数据库连接查询

Parameters

string|null $name

连接配置标识

bool $force

强制重新连接

Returns

\think\db\ConnectionInterface —

raw()

raw(string  $value) : \think\db\Raw

使用表达式设置数据

Parameters

string $value

表达式

Returns

\think\db\Raw —

updateQueryTimes()

updateQueryTimes() : void

更新查询次数

clearQueryTimes()

clearQueryTimes() : void

重置查询次数

getQueryTimes()

getQueryTimes() : int

获得查询次数

Returns

int —

listen()

listen(callable  $callback) : void

监听SQL执行

Parameters

callable $callback

回调方法

getListen()

getListen() : array

获取监听SQL执行

Returns

array —

event()

event(string  $event, callable  $callback) : void

注册回调方法

Parameters

string $event

事件名

callable $callback

回调方法

trigger()

trigger(string  $event, mixed  $params = null) : mixed

触发事件

Parameters

string $event

事件名

mixed $params

传入参数

Returns

mixed —

__call()

__call(mixed  $method, mixed  $args) : mixed

Parameters

mixed $method
mixed $args

Returns

mixed —

modelMaker()

modelMaker() : void

注入模型对象

triggerSql()

triggerSql() : void

监听SQL

instance()

instance(string|null  $name = null, bool  $force = false) : \think\db\ConnectionInterface

创建数据库连接实例

Parameters

string|null $name

连接标识

bool $force

强制重新连接

Returns

\think\db\ConnectionInterface —

getConnectionConfig()

getConnectionConfig(string  $name) : array

获取连接配置

Parameters

string $name

Returns

array —

createConnection()

createConnection( $name) : \think\db\ConnectionInterface

创建连接

Parameters

$name

Returns

\think\db\ConnectionInterface —