Home > Backend Development > PHP Tutorial > Query method of yii database

Query method of yii database

WBOY
Release: 2016-07-29 09:08:39
Original
1047 people have browsed it

The example in this article describes the query method of yii database. Share it with everyone for your reference, the details are as follows:

Here are two query methods. One is to query directly, and the other is to query using criteria.

Copy the code The code is as follows:

$user=User::model();

1. Direct query:

$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. Use criteria:

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

Copy after login

Hope this article explains It will be helpful for everyone to design PHP programs based on the yii framework.

The above introduces the query method of Yii database, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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