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.
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。
原文链接:https://www.cnblogs.com/gyfluck/p/9037337.html