dongye6377
dongye6377
2013-02-06 10:06
浏览 55
已采纳

INNODB和mysql PDO驱动程序在共享模式下锁定

With INNODB you can add to your query LOCK IN SHARE MODE; so that other users can still read but not update untill the user that is editing is finished.

My current PDO function in PHP currently looks like:

//$this->db is a PDO connection to the MYSQL innodb database.
try 
    {
    $this->db->beginTransaction();
    $tmp = $this->db->prepare($query);  

    $tmp->execute($arr);
    $this->last_id = $this->db->lastInsertId();
    $this->db->commit();
    return $this->last_id;
    }
catch(PDOException $ex)
    {
    $this->db->rollBack();
    return $ex->getMessage();
    }

Is there an PDO driver function setting to set it in share mode? if so how? The only things I find have no answers to them and the documentation isn't really clear either. Or should I add it simply to the query string?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongliang2058
    dongliang2058 2013-02-08 13:59
    已采纳

    You have to create your query to mach the MySQL syntax and that's all, for example:

    SELECT * FROM parent WHERE NAME = 'Jones' LOCK IN SHARE MODE
    

    Just append the LOCK IN SHARE MODE to the query string.

    点赞 评论

相关推荐