laravel使用ORM操作数据库


public function mode(){

  //查询所有
$isok=Student::get();



新增、


   (1)  
   $isok=Student::create([
'name'=>'123','pwd'=>'123'

]);

    (2)
$stu=new Student();
$stu->name="123";
$stu->pwd="ww";
$isok= $stu->save();

//修改

$isok= Student::where('pwd','=','56')->update([
'name'=>'123'
]);
删除

$isok=Student::where('pwd','=','56')->delete();
dd($isok);



}




//模型代码

namespace App;
use Illuminate\Database\Eloquent\Model;
class Student extends Model{


        指定表明
protected $table='test';
        允许批量赋值的字段
protected $fillable=['name','pwd'];
}
 

相关文章:

  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
猜你喜欢
  • 2021-09-06
  • 2022-01-20
  • 2021-12-21
  • 2022-12-23
  • 2021-12-23
  • 2021-10-10
相关资源
相似解决方案