Home  >  Article  >  Backend Development  >  Query method of yii database

Query method of yii database

WBOY
WBOYOriginal
2016-07-29 09:08:391016browse

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

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

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.

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