【问题标题】:How to convert this codeigniter query to select for update如何将此codeigniter查询转换为选择更新
【发布时间】:2019-01-18 17:29:05
【问题描述】:

丢失更新是一个常见的 MySQL 问题,为了解决这个问题,应该将选择查询编辑为这样的更新查询选择

select * from users where id = 1 FOR UPDATE

防止其他用户同时在同一行上工作。我想在 codeigniter 中通过将此查询编辑为更新查询的选择来做到这一点

public function get_row_data($id)
{

    $this->db->where('id',$id);

    $result = $this->db->get('users');

    if($result && $result->num_rows() > 0)
    {
        return $result->row();
    }
    else
    {
        return false;
    }
}

我可以使用上面的简单查询,但更喜欢模型查询是否可以转换。

谢谢

【问题讨论】:

  • 什么?你能说得更具体点吗?
  • 你的问题不清楚。

标签: php mysql codeigniter select


【解决方案1】:

您似乎想在Mysql中获取行级锁定 并且 codeigniter 查询生成器不允许操纵其方法来生成自定义 sql 查询

$this->db->trans_begin();
$this->db->query('you query goes here');
// other task .....
if ($this->db->trans_status() === FALSE) {
    $this->db->trans_rollback();
} else {
    $this->db->trans_commit();
}

【讨论】:

    猜你喜欢
    • 2014-01-05
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 2019-04-24
    • 2015-02-02
    • 2016-03-25
    • 1970-01-01
    相关资源
    最近更新 更多