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

yipeiwu_com6年前PHP代码库
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);

相关文章

PHP实现多个关键词搜索查询功能示例

本文实例讲述了PHP实现多个关键词搜索查询功能。分享给大家供大家参考,具体如下: PHP对于数据库的搜索主要通过使用SQL语句中的like子句来实现。如果同时搜索多个关键词,可以使用un...

PHP的简单跳转提示的实现详解

PHP的简单跳转提示的实现详解

在PHP开发中,尤其是MVC框架或者项目中,会碰到很多跳转情况,比如:登录成功或失败后的跳转等等。 以下以MVC框架开发中为基础,示例讲解: 在基础控制器类中:Conrtoller.cl...

php实现基于openssl的加密解密方法

本文实例讲述了php实现基于openssl的加密解密方法。分享给大家供大家参考,具体如下: 通过openssl加密解密方法 1. openssl加密方法: function encr...

php实现多城市切换特效

我们先来看下个人常用的代码 PHP <?php include_once('./qqwry.php'); $QQWry=new QQWry; funct...

PHP实现将多个文件中的内容合并为新文件的方法示例

本文实例讲述了PHP实现将多个文件中的内容合并为新文件的方法。分享给大家供大家参考,具体如下: function test() { $hostdir= iconv("utf-8"...