YII框架 db 操作记录
方式1:CDbCriteria
$criteria = new CDbCriteria();
$criteria->addCondition("user_id=:user_id");
$criteria->params[':user_id']= AuthorizeVerify::getUserInfo()['id'];
$data = Model::model()->findAllar($criteria);
或者
$criteria->condition = "user_id=:user_id and name=:name";
$criteria->params = array(':user_id'=>$user_id,':name'=>$name);
方法二:createCommand
users = $this->user->findAll(array(
'select'=>array('id','username','email'),
'order' => 'id DESC',
'condition' => 'state=:state AND id=:id',
'params' => array(':state'=>'1',':id' => '2'),
));
或者
$data = Yii::app()->getDb()->createCommand()
->select('type_id, type_name')
->from('table')
->where('status=1')->queryAll();
方法3:sql
$sql = "select * from table where name = ".$name;
$data = Yii::app()->db->createCommand($sql)->queryAll();