您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-查詢構造器-更新、更新或新增
发布时间:2022-02-06 20:28:28编辑:雪饮阅读()
實例:
public function index(Request $request)
{
ini_set('memory_limit','4096M');
//更新
$affected = Db::table('ecms_news')
->where('id', 1)
->update(['username' => "kasumi"]);
//更新或新增
/*
* 有时您可能希望更新数据库中的现有记录,或者如果不存在匹配记录则创建它.
* updateOrInsert 方法将首先尝试使用第一个参数的键和值对来查找匹配的数据库记录。 如果记录存在,则使用第二个参数中的值去更新记录。 如果找不到记录,将插入一个新记录,新记录的数据是两个数组的集合。
* */
$data=(Array)Db::table('ecms_news')->first();
$id=$data["id"];
unset($data["id"]);
$updateOrInsert=Db::table('ecms_news')
->updateOrInsert(
$data,
['id' => $id]
);
$all=compact("affected","updateOrInsert");
var_dump($all);
return response("ok");
}
實例被訪問時:
[root@localhost webman]# /usr/local/php734/bin/php -c /usr/local/php734/lib/php.ini start.php start
Workerman[start.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.26 PHP version:7.3.4
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root webman http://0.0.0.0:8787 4 [OK]
tcp root monitor none 1 [OK]
---------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
訪問了全局中間件!
array(2) {
["affected"]=>
int(0)
["updateOrInsert"]=>
bool(false)
}
关键字词:webman,查詢構造器,更新,新增
相关文章
- webman-查詢構造器-自增id與postgresql的序列
- webman-查詢構造器-插入
- webman-查詢構造器-offset,limit的用法
- webman-查詢構造器-groupBy與having的用法
- webman-查詢構造器-orderBy,随机排序的用法
- webman-查詢構造器-参数分组,whereExists的用法
- webman-查詢構造器-orWhereColumn 的用法
- webman-查詢構造器-whereColumn 的用法
- webman-查詢構造器-whereDate,whereMonth,whereDay,wh
- webman-查詢構造器-whereNull ,whereNotNull,orWhereN