国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開發(fā) Yii+MYSQL lock table method to prevent duplicate data under concurrency

Yii+MYSQL lock table method to prevent duplicate data under concurrency

Mar 30, 2017 pm 03:17 PM

The example of this article describes the method of Yii+MYSQL lock table to prevent duplicate data in concurrent situations. Share it with everyone for your reference, as follows:

lock table read lock

If a thread obtains a read lock on a table, then the thread and all other threads can only read locks from the table Read data, no write operations can be performed.

lock tables user read;//讀鎖定表
unlock tables;//解鎖
lock tables user read local;//本地讀鎖定表,其他線程的insert未被阻塞,update操作被阻塞

lock table write lock

If a thread obtains a write lock on a table, then only the thread that owns the lock can read from and write to the table. Other threads are blocked.

lock tables user write;//寫鎖定表
unlock tables;//解鎖

Usage examples in Yii

/**
* 當(dāng)日單項(xiàng)內(nèi)容狀態(tài)
*/
public function getPointAready($marke,$dayTime){
  $model = SysRun::model()->findByAttributes(array('syr_marking'=>$marke,'syr_daytime'=>$dayTime));
  if(empty($model)){
    //表寫鎖定
    Yii::app()->db->createCommand()->setText("lock tables {{sys_run}} WRITE")->execute();
    $model = new SysRun();
    $model->syr_marking = $marke;
    $model->syr_daytime = $dayTime;
    $model->syr_val = 0;
    $model->syr_subval = 0;
    $model->save();
    //表解鎖
    Yii::app()->db->createCommand()->setText("unlock tables")->execute();
  }
  return $model;
}

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

For more related articles on how Yii+MYSQL locks tables to prevent duplicate data under concurrency, please pay attention to the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276