search
Homephp教程php手册fleaphp crud操作之find函数的使用方法

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

Jun 13, 2016 pm 12:10 PM
crudfindcodeInstructionsfunctionprototypecopyoperateofreturn

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);

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.