Detailed information on how yii prevents concurrency-induced update data

Source: Internet
Author: User
Tags bulk insert yii
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.