更新功能:
1.对数据库表添加、修改、删除追加action。
2.添加对表结构的返回值
3.添加对FIND_IN_SET及RAW支持
数据库操作
对 Medoo Version: 2.1.10
再封装,让操作更简单。
composer require thefunpower/db_medoo
$where条件
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
where字段两个日期之间
字段是datetime类型
$date1 = '2022-11-01'; $date2 = '2022-12-14'; db_between_date($field,$date1,$date2)
where 两个月份之间
$date1 = '2022-11'; $date2 = '2022-12'; db_between_month($field,$date1,$date2
查寻一条记录
$res = db_get_one("products","*",$where); $res = db_get_one("products",$where);
所有记录
$res = db_get("products","*",$where); $res = db_get("products",$where);
分页
$res = db_pager("products","*",$where);
使用原生方法
原生方法将不会触发action
https://medoo.in/api/where
$res = db()->select("products",['id'],[]);
查寻某个字段
$res = db_get("qr_rule","qr_num",['GROUP'=>'qr_num']); print_r($res);
写入记录
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
0
更新记录
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
1
取最小值
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
2
其他一些如取最大值等
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
3
删除
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
4
action
写入记录前
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
5
写入记录后
其中$data
有 id
及 data
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
6
更新记录前
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
7
更新记录后
其中$data
有 id
data
where
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
8
'user_name[REGEXP]' => '[a-z0-9]*' 'user_name[FIND_IN_SET]'=>(string)10 'user_name[RAW]' => '[a-z0-9]*'
9
删除前
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
0
显示所有表名
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
1
取表中字段
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
2
返回数据库允许的数据,传入其他字段自动忽略
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
3
显示数据库表结构,支持markdown格式
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
4
数组排序
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
5
判断是json数据
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
6
SQL查寻
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
7
其中$sql
为select * from table_name where user_id=:user_id
$raw
为 [':user_id'=>1]
事务
需要inner db
支持
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
8
id锁
$where = [ //like查寻 'product_num[~]' => 379, //等于查寻 'product_num' => 3669, //大于查寻 'id[>]' => 1, 'id[>=]' => 1, 'id[<]' => 1, 'id[<=]' => 1, ]; $where = []; $where['OR'] = [ 'product_num[~]'=>379, 'product_num[>]'=>366, ]; $where['LIMIT'] = 10; $where['ORDER'] = ['id'=>'DESC'];
9
设置分页总记录数
$date1 = '2022-11-01'; $date2 = '2022-12-14'; db_between_date($field,$date1,$date2)
0
连表查寻
$date1 = '2022-11-01'; $date2 = '2022-12-14'; db_between_date($field,$date1,$date2)
1
db_get复杂查寻
$date1 = '2022-11-01'; $date2 = '2022-12-14'; db_between_date($field,$date1,$date2)
2
其他where条件请查看
https://medoo.in/api/where
License
The MIT License (MIT)
还没有评论,来说两句吧...