YII 框架常用语法 常用数据库操作语法
2015-10-12 22:18
561 查看
YII 框架常用数据库操作语法
/********************数据库操作的相关语法**************/
/********************查询**************/
$collect = $model->find(array('condition'=>'status > 0 ','order'=>'id desc','limit'=>5));
$collect->addtime;
Yii::app()->db->createCommand($sql)->queryAll();
Yii::app()->db->createCommand($sql)->queryRow();
Yii::app()->db->createCommand($sql)->execute();
/********************增加**************/
$model = new Industry();
$model->setAttribute('name', "");
$model->setAttribute('addtime', time());
if($model->save()){
$this->redirect('/seller/industry/index/');
Yii::app()->end();
}
/****************************统计*******************/
$num = $this->count(array("condition"=>"uid={$id} and token={$token}"));
//获取上次插入记录后的id
Yii::app()->db->getLastInsertID();
/********************修改**************/
//第一种方式
$user = new User;
$userinfo['updatetime'] = time();
$rs=$user->updateAll($userinfo, 'id=:user_id', array(':user_id'=>$user_id));
//第二种方式
public function actionUpdate($id){
$model = $this->loadModel($id);
$model->setAttribute('name', "");
$model->setAttribute('addtime', time());
if($model->save()){
$this->redirect('/seller/industry/index/');
Yii::app()->end();
}
}
public function loadModel($id)
{
$project=new Industry();
$model = $project->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
//处理报错
print_r($model->getErrors());
//获取域名
Yii::app()->request->hostInfo
//获取参数 get或者post传值
Yii::app()->request->getParam('id');
相关文章推荐
- PHP 数组常用的几个方法
- php数组
- php的self关键字和静态方法调用
- SQLSTATE[HY000] [2002] No such file or directory php连接mysql失败
- yii2 刷新页面
- activiti报错ProcessEngines.getDefaultProcessEngine()为null
- activiti报错ProcessEngines.getDefaultProcessEngine()为null
- yii学习笔记-代码流程
- 用 PHP 从 MySQL 中获取数据
- php开发日记之web表单交互
- PHP中的PDO详解
- 关于setpeer和getpeer的作用
- vsftpd配置文件详解
- 为VSFTP用户指定登录后的目录
- php操作大缓存的存储与读取
- 99 thinkphp ERR_CONTENT_DECODING_FAILED
- error C2664: “CSerialPort::InitPort”: 不能将参数 1 从“CCom_TestDlg *const ”转换为“HWND”
- PHP常用函数
- php操作rabbitmq教程
- PHP引用问题