Home > Backend Development > PHP Tutorial > yii数据库的查询方法_php实例

yii数据库的查询方法_php实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:10:14
Original
896 people have browsed it

本文实例讲述了yii数据库的查询方法。分享给大家供大家参考,具体如下:

这里介绍两种查询方法。一种是直接查询,一种是使用借助criteria实现查询。

复制代码 代码如下:
$user=User::model();

1. 直接查询:

$arr=array(
  "select"=>"username,password,email", //要查询的字段
  "condition"=>"username like '%6'", //查询条件
  "order"=>"id desc",
  "limit"=>5,
  "offset"=>1,
);
$info=$user->findAll($arr);
Copy after login

2. 使用criteria:

$criteria=new CDbCriteria();
$criteria->select="username,password,email";
$criteria->condition="username like '%1'";
$criteria->limit=5;
$criteria->order="id desc";
$criteria->offset=1;
$info=$user->findAll($criteria);

Copy after login

希望本文所述对大家基于yii框架的PHP程序设计有所帮助。

Related labels:
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