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.