fleaphp crud操作之find函数的使用方法

  find函数的原型

  

复制代码 代码如下:

  /**

  * 返回符合条件的第一条记录及所有关联的数据,查询没有结果返回 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;

  }

  find同findAll的区别在于find少了一个参数$limit,也就是说,find只会找出符合条件的第一条记录

  $conditions,

  $sort = null,

  $fields = ‘*'

  $queryLinks = true

  $conditions = null, 查询条件

  通常数组,包含字段名和值

  例如

  

复制代码 代码如下:

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

  $sort = null, 排序

  字段以及排序的方式,通常这是一个字串

  例如

  

复制代码 代码如下:

  'ID ASC,post_date DESC' //如果只有一个条件可以这样 'ID ASC'

  $fields = ‘*';, 需要查询显示的字段,默认全部显示

  例如

  

复制代码 代码如下:

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

  $queryLinks = true

  fleaphp函数find方法的使用和示例

  

复制代码 代码如下:

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

  dump($rowsets);