标签:public list() func UNC esc function usermode php5 add
//新增一条数据的方法
public function add()
{
/*$user =new UserModel();
$user->id=1;
$user->name='陈国松';
$user->email='liuyun@qq.com';
$user->birthday=strtotime('1989-7-11');
if( $user->save()){
return '用户新增成功';
}else{
return '用户新增失败';
}*/
$user['name']='看云';
$user['email']='kanyun@qq.com';
$user['birthday']=strtotime('1991-6-12');
if($result=UserModel::create($user)){
return '新增成功';
} else{
return '新增失败';
}
}
//批量新增数据
public function addList(){
$user=new UserModel();
$list=[
['name'=>'张三','email'=>'zhangsan@qq.com','birthday'=>strtotime('1978-8-9')],
['name'=>'李四','email'=>'lisi@qq.com','birthday'=>strtotime('1977-8-9')],
];
if( $user->saveAll($list)){
return '批量插入成功';
}else{
return '批量插入失败';
}
}
$user=UserModel::get(1);
$user->name='陈松';
$user->email='chensong@qq.com';
$user->save();
if($user->save()){
return '成功';
}else{
return '失败';
}
$user=new UserModel();
$user->save(['name'=>'刘涛','email'=>'liutao@qq.com'],['name'=>'陈国松']);
$user =new UserModel();
$list=[
['id'=>1, 'name'=>'thinkphp', 'email'=>'thinkphp@qq.com'],
['id'=>2, 'name'=>'onethink', 'email'=>'onethink@qq.com']
] ;
$user->isUpdate()->saveAll($list);
$user = new UserModel;
$user->where('name', '刘涛')->update(['name' => 'thinkphp']);
UserModel::where('name','thinkphp')->update(['name'=>'陈国松','email'=>'chenguosong@qq.com','birthday'=>strtotime('1997-9-16')]);
$user=UserModel::get(1);
dump($user);
echo $user->name.'</br>'.$user->email.'</br>';
$user =UserModel::get(['name'=>'陈国松']);
echo $user->email;
$user=new UserModel;
$result=$user->where('name','陈国松')->find();
echo $result->name;
$user =new Usermodel;
$result=$user->where('name','陈国松')->find();
echo $result->birthday;
$list=UserModel::all([1,2,3]);
foreach($list as $key=>$value){
echo $value->name.'</br>';
echo $value->birthday.'</br>';
echo $value->email.'</br>';
}
$user =new UserModel;
$result=$user->where('name','陈国松')->limit(2)->order('id','desc')->select();
foreach($result as $key=>$value){
echo $value['name'].'</br>';
echo $value['email'].'</br>'; }
$user=new UserModel;
echo $user->Count('id').'</br>';
echo $user->Max('id');
User::count();
User::where('status','>',0)->count();
User::where('status',1)->avg('score');
User::max('score');
$user = new User;
$user->count();
$user->where('status','>',0)->count();
$user->where('status',1)->avg('score');
$user->max('score');
标签:public list() func UNC esc function usermode php5 add
原文地址:https://www.cnblogs.com/chenguosong/p/11488631.html