thinkphp Find method queries a data record

Source: Internet
Author: User
Find ()

The thinkphp find () method is a method similar to the Select () usage, where the find () query always has only one data, that is, the system automatically adds limit 1 restrictions.

When confirming that a query's data record can only be a single record, it is recommended to use the Find () method query, such as user login account detection:

Public Function Chekuser () {    header ("content-type:text/html; Charset=utf-8 ");    $Dao = M ("User");        Constructs the query condition    $condition [' username '] = ' Admin ';    $condition [' password '] = MD5 (' 123456 ');    Query data    $list = $Dao->where ($condition)->find ();    if ($list) {        echo ' account is correct ';    } else{        echo ' account/password error ';    }}

Another difference from select () is that find () returns a one-dimensional array that can output the value of an array cell directly in the template without using a label loop output such as volist:

{$list [' username ']}

Find () Primary key query

When the condition parameter of the Find () query is a table primary key, you can write the parameter directly inside the method, such as:

$Dao = M ("User"), $list = $Dao->find (1);

The user table primary key is UID, this example will query uid=1 data, this is one of the activerecords pattern implementation, concise and intuitive.

The above describes the Thinkphp Find method query a data record, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.