laravel 操作数据库

mac2022-06-30  24

建立student控制器,控制器代码 namespace App\Http\Controllers; use Illuminate\Support\Facades\DB;class StudentController extends Controller{ //添加 public function addstudent(){ $student = DB::insert('insert into student(name,age,gender) values(?,?,?)',['张三',12,2]); var_dump($student);//成功返回bloo值true } //获取 public function getall(){// $student = DB::select('select * from student'); $student = DB::select('select * from student where id>?',[1]); return $student;//数组 } //修改 public function updstudent(){ $student = DB::update('update student set age= ? where name=?',[10,'张三']); var_dump($student);//成功返回bloo值true } //修改 public function delstudent(){ $student = DB::delete('delete from student where id=?',[10]); var_dump($student); }}

注意 laravel中return true会报错:

(1/1) UnexpectedValueException

The Response content must be a string or object implementing __toString(), "boolean" given.

转载于:https://www.cnblogs.com/gyfluck/p/9037337.html

相关资源:laravel 操作数据库常用函数的返回值方法
最新回复(0)