douyuefu1372 2019-05-01 00:59
浏览 49
已采纳

检查是否在pecee-pixie中执行了更新

I am using pecee-pixie

I run:

$result = $query_builder->where("id", "=", 4)->update($data_array);

and it executes correctly. However I want to check if the query got executed and if it failed I would like to insert the data to the array. Alas the where statements are not primary keys so i cannot use ON DUPLICATE KEY statement.

How can i check if the last query was executed with a success?

  • 写回答

1条回答 默认 最新

  • dou7851 2019-05-22 18:24
    关注

    I have never used the method before but this library has updateOrInsert method that might work. You can also easily check if the query was executed by checking the affected row count

    $result = $query_builder->where("id", "=", 4)->update($data_array);
    $count = $result->rowCount();
    if($count > 0) {
    //update executed
    } else {
    //update failed do the insert
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题