開一個網(wǎng)站建設公司外鏈工具xg
數(shù)據(jù)庫中遇到的操作
- 查詢字段是json的某個值
$map['json_extract(goods, "$.brand_id")'] = (int)$params['brand_id']; //獲取數(shù)據(jù)庫中某個字段是json中得某個值,進行查詢,goods是表中字段,brand_id是json中要查詢的字段。數(shù)據(jù)類型一定要對應要不然查詢不出來。
- 查詢結果進行遍歷操作:
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(′storep?roduct′)?>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');
-
查看數(shù)據(jù)庫中json字段不符合json結構的:
SELECT *
FROM hzqc_product_plant
WHERE JSON_VALID(goods) = 0; -
不符合json結構不能使用json_container()
-
mysql相關函數(shù):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->' .brandi?d")=6074SELECT?FROM‘hzqcp?roductp?lant‘WHERE‘storei?d‘=91000003ANDgoods?>′.“brand_id”’ = 6074;