Home > Backend Development > PHP Tutorial > How to use the find function in fleaphp crud operation_PHP tutorial

How to use the find function in fleaphp crud operation_PHP tutorial

WBOY
Release: 2016-07-21 15:30:08
Original
1155 people have browsed it

Prototype of find function

Copy code The code is as follows:

/**
* Returns the first record that meets the conditions and all associated data. If the query has no result, it returns false
*
* @param mixed $conditions
* @param string $sort
* @ param mixed $fields
* @param mixed $queryLinks
*
* @return array
*/
function & find ($conditions, $sort = null, $fields = '*', $queryLinks = true)
{
$rowset =& $this->findAll($conditions, $sort, 1, $fields, $queryLinks);
if (is_array($rowset)) {
$row = reset($rowset);
} else {
$row = false;
}
unset ($rowset);
return $row;
}

The difference between find and findAll is that find lacks one parameter $limit, that is to say, find will only find those that meet the conditions The first record of
$conditions,
$sort = null,
$fields = '*'
$queryLinks = true
$conditions = null, query conditions
usually array , including field name and value
For example
Copy code The code is as follows:

array('fieldname' => ' value1','fieldnameb' => 'value2')

$sort = null, sort the
field and the sorting method, usually this is a string
such as
Copy code The code is as follows:

'ID ASC,post_date DESC' //If there is only one condition, this can be done like this 'ID ASC'

$fields = '*';, the fields that need to be queried are displayed by default.
For example,
Copy code The code is as follows :

array('ID','post_title','post_parent')

$queryLinks = true
Usage and examples of fleaphp function find method
Copy code The code is as follows:

$rowsets = $tableposts->find(array('post_type'=>'post '),'ID ASC,post_date DESC',array('ID','post_title','post_parent'));
dump($rowsets);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323263.htmlTechArticleThe prototype copy code of the find function is as follows: /** * Returns the first record that meets the conditions and all associations The data, the query returns false * * @param mixed $conditions * @pa...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template