Home >Backend Development >PHP Tutorial >yii数据库的查询方法_PHP

yii数据库的查询方法_PHP

WBOY
WBOYOriginal
2016-05-28 11:49:56865browse

本文实例讲述了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);

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

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

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