猿问

当/如果 X 时执行 SQL 查询

我有以下插入:


        $id = \DB::table('log')

      ->insert(array(

        "account_id" => $this->get("account_id"),

        "type" => "Edit info",

        "done" => "0"

      ));

我如何调整它以便仅在日志表中没有像这样的先前条目时才执行?


account_id: 1 // 类型:编辑信息 // 完成: 0


我需要避免重复输入(如果用户已经请求编辑他/她的信息并且尚未由管理员完成,则没有相同的条目)。


元芳怎么了
浏览 132回答 1
1回答

宝慕林4294392

您可以使用updateOrInsert方法。$id = \DB::table('log')->updateOrInsert(array(  "account_id" => $this->get("account_id"),  "type" => "Edit info",  "done" => "0"));
随时随地看视频慕课网APP
我要回答