How to use the find function of the fleaphp crud operation

  • 2020-05-05 10:58:08
  • OfStack

find function prototype
 
/** 
*  Returns the first qualified record and all associated data. No results of the query are returned  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 is missing a parameter, $limit, that is, find will only find the first record that meets the criteria,
$conditions,
$sort = null,
= '*' $fields
$queryLinks = true
$conditions = null, query condition
Typically an array, containing the field name and the value
For example
 
array('fieldname' => 'value1','fieldnameb' => 'value2') 

$sort = null, sort
The fields and how they are sorted, usually this is a string
For example
 
'ID ASC,post_date DESC' // If there's only one condition that works  'ID ASC' 

$fields = '*'; , you need to query the fields displayed. By default,
is all displayed For example
 
array('ID','post_title','post_parent') 

$queryLinks = true
Use of the fleaphp function find method and sample
 
$rowsets = $tableposts->find(array('post_type'=>'post'),'ID ASC,post_date DESC',array('ID','post_title','post_parent')); 
dump($rowsets); 

Related articles: