How does yii prevent concurrency-caused update data from being denied? This paper mainly introduces the simple solution that YII can prevent the update data from concurrency, and the friend needs to refer to it. We hope to help you.
Share a useful code for YII:
When you need to make a database field increment, such as the number of daily queries, after each request to request_count+1,
If you write this:
$model->request_count++; $flag = $model->save ();
When concurrency is encountered, it is inaccurate and can be changed to:
$flag = Static::updateall ([' report_count ' = = new \yii\db\expression ("' Request_count ' + 1")], [' id ' = = $model ID]);
At the same time six processes are inserted, each process is increased 100 times, the first method only increases to 587, the second method increases to 600.
Related recommendations:
A simple extension class for bulk insert data in YII framework
Solve the query in the YII framework parameterized query only one problem
Yii solves the problem of DeleteAll even table deletion error