当前位置:网站首页>Some queries of TP5
Some queries of TP5
2022-07-27 16:22:00 【Collect and learn by yourself】
// Unwanted use app\index\model\Store;
$res = model('store')->all();
$res = collection($res)->toArray();
// need use app\index\model\Store;
$res = store::select();
$res = collection($res)->toArray();
// 6、 ... and You must specify the full table name
$res = Db::table('jh_store')->select();
// Add false Only return sql sentence Or in select prefix ->fetchSql(true) Or use getlastsql() perhaps ->buildSql();
$res = Db::table('jh_store')->select(false);
// 7、 ... and Native query
$res = Db::query("select * from jh_store where store_id=127");
// Eight can also be in table Method
$res = Db::table('tianxi.tx_admin')->where('admin_id>1')->select();
//__ Upper case table name __ Write this instead of the full table name
$res2 = Db::table('__STORE__')->select();
// Multi meter operation
$res3 = Db::field('a.store_id,a.title,b.store_goods_id,b.shop_goods_name')
->table(['jh_store'=>'a','jh_store_goods'=>'b'])
->limit(10)->select();
$res4 = Db::field('a.store_id,a.title,b.store_goods_id,b.shop_goods_name')
->table('jh_store')->alias('a')
->join('jh_store_goods b','b.store_id=a.store_id','LEFT')
->limit(10)->select();
$res5 = Db::table('jh_store_goods')->where('store_id','127')->limit(100)->select();
Db::table('think_user')->alias(['think_user'=>'user','think_dept'=>'dept'])->join('think_dept','dept.user_id= user.id')->select();
// Paging full query
$where['id'] = ['>',1];
$where['mail'] = ['like','%[email protected]%'];
$field = 'a.id,a.user_id,a.grades,a.is_involved,b.user_id,b.user_name,b.open_id,b.avatar,b.phone,c.user_id,c.alias_name';
$join = [
['tx_user b', 'a.user_id=b.user_id', 'left'],
['tx_user_info c', 'a.user_id=c.user_id', 'left']
];
$data['user'] = Db::table('tx_game_record')->alias('a')->join($join)->field($field)->where($where)->paginate(10);
$data['page'] = $data['user']->render();
$data['total'] = $data['user']->total();
// You can use functions directly in queries
$res = Db::name('order_goods')->field('order_goods_id,SUM(price)')->select();
// Field exclusion
Db::table('think_user')->field('user_id,content',true)->select();
// Or use
Db::table('think_user')->field(['user_id','content'],true)->select();
// Paging query
Db::name('order_goods')->page('1,10')->select();// Query the ten pieces of data on the first page
Db::name('order_goods')->page('2,10')->select();// Query the ten pieces of data on the second page
$res = Db::name('order_goods')->limit(10)->page(2)->select();// Query the ten pieces of data on the second page
// Merge the result set of two or more statements
$res = Db::field('name')->table('think_user')
->union('select name from think_user_1')
->union('select name from think_user_2')
//->union(['SELECT name FROM think_user_1','SELECT name FROM think_user_2'])
->select();
// Remove duplication
Db::name('user')->distinct(true)->field('name')->select();
//SQL:select distinct name from user
// to sql Statement add comments
Db::table('tp_user')
->comment(' Check the top ten students ')
->field('name')
->limit(10)
->order('id asc')
->select();边栏推荐
- centos上mysql5.7主从热备设置
- profileapi.h header
- profileapi. h header
- 使用transform:translate()出现内容模糊问题
- Leetcode25 question: turn the linked list in a group of K -- detailed explanation of the difficult questions of the linked list
- For enterprise operation and maintenance security, use the cloud housekeeper fortress machine!
- Redis简介与使用
- C语言程序设计(第三版)
- JSP Foundation
- Content ambiguity occurs when using transform:translate()
猜你喜欢

Six capabilities of test and development

Pychart imports the existing local installation package

Pychart import existing project

Time series - use tsfresh for classification tasks

Single machine high concurrency model design

2.2 basic elements of JMeter

Leetcode234 question - simple method to judge palindrome linked list

Mapreduce实例(三):数据去重

DRF learning notes (IV): DRF view

Leetcode 226 flip binary tree (recursive)
随机推荐
Rare bitwise operators
Addition, deletion, query and modification of MySQL table data
MapReduce instance (I): wordcount
Openwrt adds support for SD card
scrapy爬虫框架
实现浅拷贝和深拷贝+
The difference and use between get request and post request
百度图片复制图片地址
Delete node quickly and efficiently_ modules
解决MT7620不断循环uboot(LZMA ERROR 1 - must RESET board to recover)
Personal perception of project optimization
Scratch crawler framework
ARIMA模型选择与残差
Constraints, design and joint query of data table -- 8000 word strategy + Exercise answers
The 4.3 billion euro cash acquisition of OSRAM failed! AMS said it would continue to acquire
Leetcode25 question: turn the linked list in a group of K -- detailed explanation of the difficult questions of the linked list
DeFi安全之DEX与AMMs
const小结
Penetration test - dry goods | 80 + network security interview experience post (interview)
SQL multi table query