YII框架数据库的增删改查
//添加
Yii::app()->db->createCommand()->insert('tbl_user',
array(
'username' => 'zhangsan',
'email' => 'zhangsan@zs.com'));
//使用user model添加数据
$user = new Users();
$user->setAttributes(array(
'username' => 'user1',
'email' => '123@qq.com',
'password'=>md5("abcsd5a4"),
'last_login'=>time()
));
$user->save()
//修改
Yii::app()->db->createCommand()->update('tbl_user',
array(
'username' => 'Tester'), 'id=:id', array(
':id' => 3));
//删除
Yii::app()->db->createCommand()->delete('tbl_user', 'id=:id',
array(
':id' => 2));
//查询 - 多条数据
$users = Yii::app()->db->createCommand()
->select('*')
->from('tbl_user')
->queryAll();
//查询一条数据
$sql = "SELECT id,name FROM tbl_user WHERE email='123@qq.com' ";
$users=Yii::app()->db->createCommand($sql)->queryRow();
var_dump($users);