function.php
对数据库操作的封装 https://medoo.in/api/where
Table of Contents
Classes
- medoo_paginate
- <code> 类似淘宝分页
Functions
- db_active_main() : mixed
- 激活平台数据库连接,平台数据库不支持从库读
- db_active_read() : mixed
- 激活读数据库连接
- db_active_default() : mixed
- 激活默认数据库连接
- db_prefix() : mixed
- 表前缀
- get_db_table_name() : mixed
- 表名
- db_active() : mixed
- 激活当前使用哪个数据库
- db_active_rollback() : mixed
- 回到上一个连接
- get_db_active_name() : mixed
- 获取当前启用的数据库连接
- db_can_run_action() : mixed
- 判断是否可运行action
- db_can_run_update() : mixed
- 数据库是否可执行更新操作
- new_db() : mixed
- 连接数据库
- medoo_db() : object
- 数据库实例
- db() : mixed
- db_pager() : mixed
- db_pager_count() : mixed
- 设置分页总记录数 一般情况用不到
- db_pager_html() : mixed
- 显示分页 调用db_pager后,再调用。 db_pager_html([ 'url'=>'', ]);
- db_add_error() : mixed
- 添加错误信息
- db_get_error() : mixed
- 获取错误信息
- db_get_fast() : mixed
- db_get() : mixed
- db_select() : mixed
- $lists = db_select('do_order', [ 'count' => 'COUNT(`id`)', 'total' => 'SUM(`total_fee`)', 'date' => "FROM_UNIXTIME(`inserttime`, '%Y-%m-%d')" ], 'WHERE `status` = 1 GROUP BY `date` LIMIT 30' );
- db_insert() : array<string|int, mixed>
- 写入记录
- db_update() : array<string|int, mixed>
- 更新记录
- db_action() : mixed
- 数据库事务
- db_for_update() : mixed
- 对数据进行
- db_get_one() : array<string|int, mixed>
- 根据表名、字段 、条件 查寻一条记录
- db_query() : mixed
- SQL查寻
- db_get_min() : void
- 取最小值 https://medoo.in/api/min min($table, $column, $where) min($table, $join, $column, $where)
- db_get_max() : void
- 取最大值 max($table, $column, $where) max($table, $join, $column, $where)
- db_get_count() : void
- 总数 count($table, $where) count($table, $join, $column, $where)
- db_get_has() : void
- 是否有记录 has($table, $where) has($table, $join, $where)
- db_get_rand() : void
- 随机取多条记录 rand($table, $column, $where) rand($table, $join, $column, $where)
- db_get_sum() : void
- 取总和 sum($table, $column, $where) sum($table, $join, $column, $where)
- db_get_avg() : void
- 取平均值 avg($table, $column, $where) avg($table, $join, $column, $where)
- db_raw() : mixed
- RAW https://medoo.in/api/raw raw('NOW()') raw('RAND()') raw('AVG(<age>)')
- db_del() : mixed
- db_delete() : mixed
- show_tables() : void
- 显示所有表名
- get_table_fields() : mixed
- 取表中字段
- db_allow() : mixed
- 返回数据库允许的数据,传入其他字段自动忽略
- database_tables() : mixed
- 显示数据库表结构,支持markdown格式
- get_table_field_json() : mixed
- 取表中json字段
- get_table_field_is_json() : mixed
- 判断表中的字段是不是json
- db_row_json_to_array() : mixed
- 把数据库中json字段转成array
- array_order_by() : mixed
- is_json() : mixed
- add_action() : mixed
- do_action() : mixed
- db_between_date() : mixed
- 返回两个日期之间 $date1 = '2022-11-01'; $date2 = '2022-12-14'; 字段是datetime类型
- db_between_month() : mixed
- 返回两个月份之间 $date1 = '2022-11'; $date2 = '2022-12'; 字段是datetime类型
- xa_db_action() : mixed
- 跨库数据库事务
- db_struct_table_range_auto() : mixed
- 创建分区表,自动排除已有的
- db_struct_table_range() : mixed
- 创建分区表,内部调用 db_struct_table_range('my_table',[ '2023-11', '2023-12', '2024-01', ],'created_at','p',false);
- db_struct_show_range() : mixed
- 分区表名称
- drop_struct_range() : mixed
- 删除某个分区表 删除后分区数据也会一起删除
- db_show_create_table() : mixed
- 显示create table语句
Functions
db_active_main()
激活平台数据库连接,平台数据库不支持从库读
db_active_main() : mixed
db_active_read()
激活读数据库连接
db_active_read() : mixed
db_active_default()
激活默认数据库连接
db_active_default() : mixed
db_prefix()
表前缀
db_prefix([mixed $prefix = null ]) : mixed
Parameters
- $prefix : mixed = null
get_db_table_name()
表名
get_db_table_name(mixed $table) : mixed
Parameters
- $table : mixed
db_active()
激活当前使用哪个数据库
db_active([mixed $name = 'default' ][, mixed $need_rollback_here = false ]) : mixed
Parameters
- $name : mixed = 'default'
- $need_rollback_here : mixed = false
db_active_rollback()
回到上一个连接
db_active_rollback() : mixed
get_db_active_name()
获取当前启用的数据库连接
get_db_active_name() : mixed
db_can_run_action()
判断是否可运行action
db_can_run_action() : mixed
db_can_run_update()
数据库是否可执行更新操作
db_can_run_update([mixed $sql = '' ]) : mixed
Parameters
- $sql : mixed = ''
new_db()
连接数据库
new_db([mixed $config = [] ][, mixed $name = '' ]) : mixed
Parameters
- $config : mixed = []
- $name : mixed = ''
medoo_db()
数据库实例
medoo_db() : object
Return values
objectdb()
db() : mixed
db_pager()
db_pager(mixed $table, mixed $join[, mixed $columns = null ][, mixed $where = null ]) : mixed
Parameters
- $table : mixed
- $join : mixed
- $columns : mixed = null
- $where : mixed = null
db_pager_count()
设置分页总记录数 一般情况用不到
db_pager_count([mixed $nums = null ]) : mixed
Parameters
- $nums : mixed = null
db_pager_html()
显示分页 调用db_pager后,再调用。 db_pager_html([ 'url'=>'', ]);
db_pager_html([mixed $arr = [] ]) : mixed
Parameters
- $arr : mixed = []
db_add_error()
添加错误信息
db_add_error(mixed $str) : mixed
Parameters
- $str : mixed
db_get_error()
获取错误信息
db_get_error() : mixed
db_get_fast()
db_get_fast(mixed $table[, mixed $join = null ][, mixed $columns = null ][, mixed $where = null ]) : mixed
Parameters
- $table : mixed
- $join : mixed = null
- $columns : mixed = null
- $where : mixed = null
db_get()
db_get(mixed $table[, mixed $join = null ][, mixed $columns = null ][, mixed $where = null ]) : mixed
Parameters
- $table : mixed
- $join : mixed = null
- $columns : mixed = null
- $where : mixed = null
db_select()
$lists = db_select('do_order', [ 'count' => 'COUNT(`id`)', 'total' => 'SUM(`total_fee`)', 'date' => "FROM_UNIXTIME(`inserttime`, '%Y-%m-%d')" ], 'WHERE `status` = 1 GROUP BY `date` LIMIT 30' );
db_select(mixed $table[, mixed $join = "*" ][, mixed $columns = null ][, mixed $where = null ]) : mixed
Parameters
- $table : mixed
- $join : mixed = "*"
- $columns : mixed = null
- $where : mixed = null
db_insert()
写入记录
db_insert(string $table[, array<string|int, mixed> $data = [] ][, mixed $don_run_action = false ]) : array<string|int, mixed>
Parameters
- $table : string
-
表名
- $data : array<string|int, mixed> = []
-
数据
- $don_run_action : mixed = false
Return values
array<string|int, mixed>db_update()
更新记录
db_update(string $table[, array<string|int, mixed> $data = [] ][, mixed $where = [] ][, mixed $don_run_action = false ]) : array<string|int, mixed>
Parameters
- $table : string
-
表名
- $data : array<string|int, mixed> = []
-
数据
- $where : mixed = []
- $don_run_action : mixed = false
Return values
array<string|int, mixed>db_action()
数据库事务
db_action(mixed $call) : mixed
Parameters
- $call : mixed
db_for_update()
对数据进行
db_for_update(mixed $table, mixed $id) : mixed
Parameters
- $table : mixed
- $id : mixed
db_get_one()
根据表名、字段 、条件 查寻一条记录
db_get_one(string $table[, mixed $join = "*" ][, mixed $columns = null ][, array<string|int, mixed> $where = null ]) : array<string|int, mixed>
Parameters
- $table : string
-
表名
- $join : mixed = "*"
- $columns : mixed = null
- $where : array<string|int, mixed> = null
-
条件
Return values
array<string|int, mixed>db_query()
SQL查寻
db_query(mixed $sql[, mixed $raw = null ]) : mixed
Parameters
- $sql : mixed
- $raw : mixed = null
db_get_min()
取最小值 https://medoo.in/api/min min($table, $column, $where) min($table, $join, $column, $where)
db_get_min(string $table[, mixed $join = "*" ][, string $column = null ][, array<string|int, mixed> $where = null ]) : void
Parameters
- $table : string
-
表名
- $join : mixed = "*"
- $column : string = null
-
字段
- $where : array<string|int, mixed> = null
-
条件
db_get_max()
取最大值 max($table, $column, $where) max($table, $join, $column, $where)
db_get_max(string $table[, mixed $join = "*" ][, string $column = null ][, array<string|int, mixed> $where = null ]) : void
Parameters
- $table : string
-
表名
- $join : mixed = "*"
- $column : string = null
-
字段
- $where : array<string|int, mixed> = null
-
条件
db_get_count()
总数 count($table, $where) count($table, $join, $column, $where)
db_get_count(string $table[, mixed $join = "*" ][, mixed $column = null ][, array<string|int, mixed> $where = null ]) : void
Parameters
- $table : string
-
表名
- $join : mixed = "*"
- $column : mixed = null
- $where : array<string|int, mixed> = null
-
条件
db_get_has()
是否有记录 has($table, $where) has($table, $join, $where)
db_get_has(string $table[, mixed $join = null ][, array<string|int, mixed> $where = null ]) : void
Parameters
- $table : string
-
表名
- $join : mixed = null
- $where : array<string|int, mixed> = null
-
条件
db_get_rand()
随机取多条记录 rand($table, $column, $where) rand($table, $join, $column, $where)
db_get_rand(string $table[, mixed $join = "*" ][, string $column = null ][, array<string|int, mixed> $where = null ]) : void
Parameters
- $table : string
-
表名
- $join : mixed = "*"
- $column : string = null
-
字段
- $where : array<string|int, mixed> = null
-
条件
db_get_sum()
取总和 sum($table, $column, $where) sum($table, $join, $column, $where)
db_get_sum(string $table[, mixed $join = "*" ][, string $column = null ][, array<string|int, mixed> $where = null ]) : void
Parameters
- $table : string
-
表名
- $join : mixed = "*"
- $column : string = null
-
字段
- $where : array<string|int, mixed> = null
-
条件
db_get_avg()
取平均值 avg($table, $column, $where) avg($table, $join, $column, $where)
db_get_avg(string $table[, mixed $join = "*" ][, string $column = null ][, array<string|int, mixed> $where = null ]) : void
Parameters
- $table : string
-
表名
- $join : mixed = "*"
- $column : string = null
-
字段
- $where : array<string|int, mixed> = null
-
条件
db_raw()
RAW https://medoo.in/api/raw raw('NOW()') raw('RAND()') raw('AVG(<age>)')
db_raw(string $raw) : mixed
Parameters
- $raw : string
db_del()
db_del(mixed $table, mixed $where) : mixed
Parameters
- $table : mixed
- $where : mixed
db_delete()
db_delete(mixed $table, mixed $where) : mixed
Parameters
- $table : mixed
- $where : mixed
show_tables()
显示所有表名
show_tables(string $table) : void
Parameters
- $table : string
-
表名
Tags
get_table_fields()
取表中字段
get_table_fields(mixed $table[, mixed $has_key = true ]) : mixed
Parameters
- $table : mixed
- $has_key : mixed = true
db_allow()
返回数据库允许的数据,传入其他字段自动忽略
db_allow(mixed $table, mixed $data) : mixed
Parameters
- $table : mixed
- $data : mixed
database_tables()
显示数据库表结构,支持markdown格式
database_tables([string $name = null ][, mixed $show_markdown = false ]) : mixed
Parameters
- $name : string = null
-
数据库名
- $show_markdown : mixed = false
Tags
get_table_field_json()
取表中json字段
get_table_field_json(mixed $table) : mixed
Parameters
- $table : mixed
get_table_field_is_json()
判断表中的字段是不是json
get_table_field_is_json(mixed $table, mixed $field) : mixed
Parameters
- $table : mixed
- $field : mixed
db_row_json_to_array()
把数据库中json字段转成array
db_row_json_to_array( $table_name[, &$row_data = [] ]) : mixed
Parameters
array_order_by()
array_order_by() : mixed
is_json()
is_json(mixed $data[, mixed $assoc = false ]) : mixed
Parameters
- $data : mixed
- $assoc : mixed = false
add_action()
add_action(mixed $name, mixed $call[, mixed $level = 20 ]) : mixed
Parameters
- $name : mixed
- $call : mixed
- $level : mixed = 20
do_action()
do_action(mixed $name[, mixed &$par = null ]) : mixed
Parameters
- $name : mixed
- $par : mixed = null
db_between_date()
返回两个日期之间 $date1 = '2022-11-01'; $date2 = '2022-12-14'; 字段是datetime类型
db_between_date(mixed $field, mixed $date1, mixed $date2) : mixed
Parameters
- $field : mixed
- $date1 : mixed
- $date2 : mixed
db_between_month()
返回两个月份之间 $date1 = '2022-11'; $date2 = '2022-12'; 字段是datetime类型
db_between_month(mixed $field, mixed $date1, mixed $date2) : mixed
Parameters
- $field : mixed
- $date1 : mixed
- $date2 : mixed
xa_db_action()
跨库数据库事务
xa_db_action([mixed $key_call = [] ]) : mixed
Parameters
- $key_call : mixed = []
db_struct_table_range_auto()
创建分区表,自动排除已有的
db_struct_table_range_auto(mixed $db_name, mixed $table[, mixed $year_month = [] ][, mixed $datetime_field = 'created_at' ][, mixed $name = 'p' ]) : mixed
db_struct_table_range_auto('wordpress','my_table',[ '2023-11', '2023-12', '2024-01', '2024-02', '2024-03', ]);
Parameters
- $db_name : mixed
- $table : mixed
- $year_month : mixed = []
- $datetime_field : mixed = 'created_at'
- $name : mixed = 'p'
db_struct_table_range()
创建分区表,内部调用 db_struct_table_range('my_table',[ '2023-11', '2023-12', '2024-01', ],'created_at','p',false);
db_struct_table_range(mixed $table[, mixed $year_month = [] ][, mixed $datetime_field = 'created_at' ][, mixed $name = 'p' ][, mixed $return_sql = false ]) : mixed
Parameters
- $table : mixed
- $year_month : mixed = []
- $datetime_field : mixed = 'created_at'
- $name : mixed = 'p'
- $return_sql : mixed = false
db_struct_show_range()
分区表名称
db_struct_show_range([mixed $db_name = '' ][, mixed $table = '' ]) : mixed
Parameters
- $db_name : mixed = ''
- $table : mixed = ''
drop_struct_range()
删除某个分区表 删除后分区数据也会一起删除
drop_struct_range(mixed $table, mixed $p) : mixed
Parameters
- $table : mixed
- $p : mixed
db_show_create_table()
显示create table语句
db_show_create_table(mixed $table[, mixed $return_val = true ]) : mixed
Parameters
- $table : mixed
- $return_val : mixed = true