我正在使用pecee-pixie
我运行:
$result = $query_builder->where("id", "=", 4)->update($data_array);并且它可以正确地执行。但是,我希望检查查询是否已执行,如果失败,我希望将数据插入数组。遗憾的是,where语句不是主键,所以我不能使用ON DUPLICATE KEY语句。
如何检查上一次查询是否执行成功?
发布于 2019-05-23 02:24:50
我以前从来没有用过这个方法,但是这个库有updateOrInsert方法,也许可以用。您还可以通过检查受影响的行数轻松地检查查询是否已执行
$result = $query_builder->where("id", "=", 4)->update($data_array);
$count = $result->rowCount();
if($count > 0) {
//update executed
} else {
//update failed do the insert
}https://stackoverflow.com/questions/55930451
复制相似问题