在用原生写脚本的时候怀念起框架中封装好的ORM,所以仿照laravel写了这个简版的ORM,可以链式操作。
DB::table('class as c')
->select('c.name as class_name', 's.name as student_name', 's.age', 's.sex')
->leftJoin('relation_class_students as r', 'r.class_id', '=', 'c.id')
->leftJoin('students as s', 'r.student_id', '=', 's.id')
->where('c.grade', 1)
->where('c.class', 1)
->get();
DB::table('class')
->where('grade', 2)
->where('class', 1)
->update([
'teach' => '李老师',
]);
DB::table('class')
->insert([
'grade' => 3,
'class' => 1,
'name' => '三年1班'
'teach' => '李老师',
]);
composer require xhxhx/mypro v1.0.2
- table()
- select()
- leftJoin()
- where() 支持数组或多参数形式
- orWhere()
- whereIn
- whereBetween
- group()
- order()
- offset()
- limit()
###操作函数
- count()
- findIt()
- find()
- get()
- insert()
- update()
- delete()
数据库配置在Config/db_config中