fastadmin常用操作
数据库中遇到的操作
- 查询字段是json的某个值
$map['json_extract(goods, "$.brand_id")'] = (int)$params['brand_id']; //获取数据库中某个字段是json中得某个值,进行查询,goods是表中字段,brand_id是json中要查詢的字段。数据类型一定要对应要不然查询不出来。
- 查询结果进行遍历操作:
db('product_plant')->where($map)->order('id', 'desc')->paginate($limit)->each(function ($item, $key) use ($store_id) {
//代码逻辑
}
- 多级下拉
if (isset($params['cat']) && !empty($params['cat'])) {
if (count($params['cat']) == 1) {
$shop_cat_array = model('store_category')->where(['pid'=>$params['cat'][0], 'store_id'=>$this->auth->id])->column('id');
$cat = model('store_category')->where('pid', 'in', $shop_cat_array)->where('store_id', $this->auth->id)->column('id');
$map['shop_cat'] = ['in', $cat];
}
else if (count($params['cat']) == 2) {
$cat = model('store_category')->where(['pid'=>$params['cat'][1], 'store_id'=>$this->auth->id])->column('id');
$map['shop_cat'] = ['in', $cat];
}
else {
$map['shop_cat'] = $params['cat'][2];
}
}
$field = ‘p.id’;
s
q
l
=
d
b
(
′
p
r
o
d
u
c
t
′
)
−
>
a
l
i
a
s
(
′
p
′
)
−
>
f
i
e
l
d
(
sql = db('product')->alias('p')->field(
sql=db(′product′)−>alias(′p′)−>field(field)->where(
w
h
e
r
e
)
−
>
u
n
i
o
n
(
f
u
n
c
t
i
o
n
(
where)->union(function (
where)−>union(function(query) use (
w
h
e
r
e
,
where,
where,field) {
q
u
e
r
y
−
>
n
a
m
e
(
′
s
t
o
r
e
p
r
o
d
u
c
t
′
)
−
>
a
l
i
a
s
(
′
p
′
)
−
>
f
i
e
l
d
(
query->name('store_product')->alias('p')->field(
query−>name(′storeproduct′)−>alias(′p′)−>field(field)->where($where);
}, true)->buildSql();
m
o
d
e
l
=
D
b
:
:
t
a
b
l
e
(
model = Db::table(
model=Db::table(sql . ’ as a’);
$productIds = $model->column(‘id’);
$map[‘product_id’] = [‘in’, $productIds];
$this->request->domain()
$bill_money = db('store_bill')->where(array_merge(['comein'=>1],$w))->sum('price')
-db('store_bill')->where(array_merge(['comein'=>0],$w))->sum('price');
-
查看数据库中json字段不符合json结构的:
SELECT *
FROM hzqc_product_plant
WHERE JSON_VALID(goods) = 0; -
不符合json结构不能使用json_container()
-
mysql相关函数:json_valid()
-
php密码设置
$params[‘salt’] = Random::alnum();
p a r a m s [ ′ p a s s w o r d ′ ] = m d 5 ( m d 5 ( params['password'] = md5(md5( params[′password′]=md5(md5(params[‘password’]) . $params[‘salt’]);
SELECT * FROM hzqc_product_plant
WHERE store_id
= 91000003 AND json_extract(goods, "
.
b
r
a
n
d
i
d
"
)
=
6074
S
E
L
E
C
T
∗
F
R
O
M
‘
h
z
q
c
p
r
o
d
u
c
t
p
l
a
n
t
‘
W
H
E
R
E
‘
s
t
o
r
e
i
d
‘
=
91000003
A
N
D
g
o
o
d
s
−
>
′
.brand_id") = 6074 SELECT * FROM `hzqc_product_plant` WHERE `store_id` = 91000003 AND goods->'
.brandid")=6074SELECT∗FROM‘hzqcproductplant‘WHERE‘storeid‘=91000003ANDgoods−>′.“brand_id”’ = 6074;
原文地址:https://blog.csdn.net/weixin_40534405/article/details/143729185
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!