YII框架数据库的增删改查
时间:2021-07-01 10:21:17
帮助过:12人阅读
Yii::app()->db->createCommand()->insert(‘tbl_user‘,
array(
‘username‘ => ‘zhangsan‘,
‘email‘ => ‘zhangsan@zs.com‘));
$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);
YII框架数据库的增删改查
标签: