Search data optimization of Thinkphpwhere () method

Source: Internet
Author: User
Method 1 {code ...} method 2 {code ...} both methods can implement the operations I want, but the first method will put pressure on the server or database. The second method is to write more code {code ...} the first method in tangle

$ Bank = array (12) {["bank_id"] => string (1) "9" ["bank_type"] => string (1) "1" ["bank_operator_id"] => string (1) "2" ["bank_operator_name"] => string (9) "Tang Xinpeng" ["bank_operator_type"] => string (1) "3" ["bank_accept_id"] => string (1) "1" ["bank_accept_name"] => string (9) "Wang Changning" ["bank_accept_type"] => string (1) "1" ["bank_sum"] => string (5) "50000" ["bank_mark"] => string (3) "500" ["bank_confirm"] => string (1) "0" ["bank_create_time"] => string (10) "1467113725"} $ m-> where ($ bank)-> setField ('Bank _ confirm', '1 ');

Method 2

$ Bank = array (12) {["bank_id"] => string (1) "9" ["bank_type"] => string (1) "1" ["bank_operator_id"] => string (1) "2" ["bank_operator_name"] => string (9) "Tang Xinpeng" ["bank_operator_type"] => string (1) "3" ["bank_accept_id"] => string (1) "1" ["bank_accept_name"] => string (9) "Wang Changning" ["bank_accept_type"] => string (1) "1" ["bank_sum"] => string (5) "50000" ["bank_mark"] => string (3) "500" ["bank_confirm"] => string (1) "0" ["bank_create_time"] => string (10) "1467113725"} $ condition ['bank _ id'] = $ bank ["bank_id"]; $ m-> where ($ condition) -> setField ('Bank _ confirm', '1 ');

Both methods can implement the operations I want,
The first method causes pressure on the server or database

Second, you can write more code.

$condition['bank_id'] = $bank["bank_id"];

Tangle)

Reply content:

Method 1

$ Bank = array (12) {["bank_id"] => string (1) "9" ["bank_type"] => string (1) "1" ["bank_operator_id"] => string (1) "2" ["bank_operator_name"] => string (9) "Tang Xinpeng" ["bank_operator_type"] => string (1) "3" ["bank_accept_id"] => string (1) "1" ["bank_accept_name"] => string (9) "Wang Changning" ["bank_accept_type"] => string (1) "1" ["bank_sum"] => string (5) "50000" ["bank_mark"] => string (3) "500" ["bank_confirm"] => string (1) "0" ["bank_create_time"] => string (10) "1467113725"} $ m-> where ($ bank)-> setField ('Bank _ confirm', '1 ');

Method 2

$ Bank = array (12) {["bank_id"] => string (1) "9" ["bank_type"] => string (1) "1" ["bank_operator_id"] => string (1) "2" ["bank_operator_name"] => string (9) "Tang Xinpeng" ["bank_operator_type"] => string (1) "3" ["bank_accept_id"] => string (1) "1" ["bank_accept_name"] => string (9) "Wang Changning" ["bank_accept_type"] => string (1) "1" ["bank_sum"] => string (5) "50000" ["bank_mark"] => string (3) "500" ["bank_confirm"] => string (1) "0" ["bank_create_time"] => string (10) "1467113725"} $ condition ['bank _ id'] = $ bank ["bank_id"]; $ m-> where ($ condition) -> setField ('Bank _ confirm', '1 ');

Both methods can implement the operations I want,
The first method causes pressure on the server or database

Second, you can write more code.

$condition['bank_id'] = $bank["bank_id"];

Tangle)

Thank you for your invitation. I do not knowbank_idIs it unique? if it is the only second condition, it is enough. Although many of your first conditions have high query accuracy, I think they arestringType. if there is an index, it is fine. if there is no index, I suggest the second one if one condition is sufficient.

Thank you! bank_id must be a unique key or primary key.
$m->where(array('bank_id' => $bank['bank_id']))->setField('bank_confirm','1');

The upstairs has answered your question correctly. if bank_id is the unique key, the single-condition query is performed.

In theory, the more query conditions, the more data is filtered, and the faster the query. However, if you have a primary key or index Field and add limit = 1, the efficiency is enough.

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.