Home >php教程 >php手册 >判断存在记录,并加锁防止其他进程新增或者更新

判断存在记录,并加锁防止其他进程新增或者更新

WBOY
WBOYOriginal
2016-06-06 19:35:321391browse

项目中一段保存配置weixinappid代码,都来吐几句吧 无 /** * 判断是否有$company_id公司的微信配置,并加锁,防止其他进程更新新增 */ public function exists_weixin_config_and_add_row_lock($company_id){ return $this-db-query( 'SELECT EXISTS( SELECT

项目中一段保存配置weixin appid代码,都来吐几句吧
    /**
     * 判断是否有$company_id公司的微信配置,并加锁,防止其他进程更新新增
     */
    public function exists_weixin_config_and_add_row_lock($company_id){
        return $this->db->query(
            'SELECT EXISTS(
                SELECT * FROM weixin_config WHERE company_id = ? FOR UPDATE
                ) AS has',
            array($company_id))->row()->has == 1;
    }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn