tp5的資料查詢語言

2021-08-13 23:57:30 字數 1753 閱讀 4438

$result = db::name('log')

->where('id', 2)

->find();

//多條件查詢

//中間引數可以寫成 >= <= <> in [4,5,6,7] 'between' [5,8]

$result = db::name('log')

->where('id', '>=', 2)

->select();

$result = db::name('log')

->where('id', 'in', [102,103,104])

->select();

$result = db::name('log')

->where('id', 'exp', '>1 and user_id = 1')

->select();

$result = db::name('log')

->where('id', '>=', '1')

->where('user_id', '1')

->select();

或者:$result = db::name('log')

->where([

'id' => ['>=', 1],

'ip' => ['like', '%1%'],

])->select();

$result = db::name('log')

->where('ip', 'like', '%1%')

->where('id', ['in', [1,2,3]], ['>=', 1], 'or')

->limit(2)

->select();

//如果要查詢id和user_id同時大於1的的項,可以像下面這樣寫

$result = db::name('log')

->where('id&user_id', '>', 1)

->limit(10)

->select();

//如果要查詢id大於1或者user_id大於1的的項,可以像下面這樣寫

$result = db::name('log')

->where('id|user_id', '>', 1)

->limit(10)

->select();

//獲取某行

+的某個值

$name = db::name('log')

->where('id', 102)

->value('user_id');

//獲取某列的某個值

$name = db::name('log')

->where('user_id', 1)

->column('ip');

$result = $name;

$count = db::name('log')->where('user_id', 1)->count();

在model中的**

protected function scopeip($query)

protected function scopeuserid($query)

TP5使用模型查詢資料

前提 引入model 1.get 方法,引數為 主鍵值 res user get 1 toarray 方法是將 get的值,轉為陣列 res res toarray get 方法還支援閉包 res user get function query res res toarray dump res 2....

tp5查詢,新增,刪除語句

tp5新增 use think db db name 表名 isert input post.db table 完整表名 isert input post.db 表名 insert input post.tp5查詢 引入助手函式 use think db 找到模型的位置 查詢id 1點全部資料資訊 ...

tp5 資料庫Db查詢操作

data db query select from tf action data db query select from tf action where id and id 1,10 sql db getlastsql 查詢用query。刪除,增加,修改,用execute。data db tabl...