-
php的orm關(guān)聯(lián)table
查看全部 -
查詢構(gòu)造器中的聚合函數(shù)
count()????max()????min()????avg()????sum()
DB::table('student')->count();????//總條數(shù)
DB::table('student')->max('age');????//最大值
DB::table('student')->min('age');????//最小值
DB::table('student')->avg('age');????//平均值
DB::table('student')->sum('age');????//總和
查看全部 -
查詢構(gòu)造器查詢數(shù)據(jù)方法
get()????first()????where()????pluck()? ? lists()????select()?? ? chunk()
orderBy('id','desc')????這個是排序方法 ?desc是降敘 ? ? asce升序
whereRaw() 添加個條件whereRaw('id>=? and age >?',[1001,18])
$students = DB::table('student')->get();????//返回所有數(shù)據(jù)
$students = DB::table('student')->first();????//返回首條數(shù)據(jù),一條數(shù)據(jù)
$students = DB::table('student')->where('id','>=',10)->get();//單個條件
$students = DB::table('student')->whereRaw('id>=? and age >?',[1001,18])->get();//多條件
$students = DB::table('student')->pluck('字段');????//只返回某一字段的值
$students = DB::table('student')->lists('字段');????//返回某一字段的值 ?與pluck區(qū)別在與可以指定下標(biāo)如lists('字段','下標(biāo)的字段');
$students = DB::table('student')->select('字段','字段')->get();//查詢的字段
DB::table('student')->chunk(2,function($studnets){
????var_dump($students);
}); ? //每次查詢的幾條數(shù)據(jù) 顯示
查看全部 -
查詢構(gòu)造器刪除數(shù)據(jù)
$num = DB::('student')->delete(); ? //刪除所有數(shù)據(jù)
$num = DB::('student')->where('id',15)->delete();//刪除指定id的數(shù)據(jù)
$num = DB::('student')->where('id,'>=',12)->delete();//條件刪除
DB::table('student')->truncate(); ?//清空數(shù)據(jù)表,沒有返回值
查看全部 -
更新字段
$num = DB::table('表名')->where('id',12)->update(['age'=>30]);
自增
$num = DB::table('表名')->increment('age',增加的數(shù)值,默認(rèn)是1);
自減
$num = DB::table('表名')->decrement('age',自減默認(rèn)是1);
在實現(xiàn)自增和自減的同時修改其他的字段修改條件添加
$num = DB::table('表名')->where('id',12)->decrement('age',自減默認(rèn)是1,['name'=>'imooc');
查看全部 -
查詢構(gòu)造器***
1、查詢構(gòu)造器簡
查詢構(gòu)造器提供方便,流暢的接口,簡歷及執(zhí)行數(shù)據(jù)庫查找語法
PDO參數(shù)綁定,保護(hù)程序面SQL注入,傳入?yún)?shù)不需要轉(zhuǎn)義字符
在所有支持的數(shù)據(jù)庫系統(tǒng)上都可以執(zhí)行
查詢構(gòu)造器插入方法:
1、$bool = DB::table('需要查詢的表')->insert(['字段1'=>'值','字段2'=>'值']); ?//插入一條數(shù)據(jù),返回值是bool值
2、$id = DB::table('需要查詢的表')->insertGetId(['字段1'=>'值','字段2'=>'值']); ? //插入一條數(shù)據(jù),返回的插入的ID ? insertGetId
3、$bool = DB::table('需要查詢的表')->insert([
????????????['字段1'=>'值','字段2'=>'值'],
????????????['字段1'=>'值','字段2'=>'值']
]); //添加中括號,以數(shù)組的形式插入就可以插入多條數(shù)據(jù)了
查看全部 -
Laravel框架哥哥版本對PHP的要求
5.1 5.2????php5.5.9+
4.2????????? php5.4+
4.1????????? ?php5.3.7+
查看全部 -
連接數(shù)據(jù)庫
配置文件:/config/database.php
'database'=>env('DB_DATABASE','forge')
env 對應(yīng)的是 /.env文件配置
查看全部 -
Eloquent ORM 使用方法
1、數(shù)據(jù)庫的配置文件在\config\database.php文件中
.env 表中可以更改一下數(shù)據(jù)庫的連接
1、模型建立
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Student extends Model
{
????//指定表名?
????protected $table = 'student';
????//指定 主鍵?
????protected $primaryKey = 'id';
}
2、使用 ORM的方方法
Student::all(); ? //查詢?nèi)?/p>
Student::find('id'); ?//查詢一條ID的記錄
Student::findeorFail('id') //查詢Id 查詢不到報錯
Student::get(); ? ?//查詢構(gòu)造器全部
Student ::where('id','條件',' 數(shù)據(jù)')
????????????????->orderBy('age','desc')
????????????????->first()
Student::chunk(查詢條數(shù),function($studnets){
????var_dump($students);
});
//聚合函數(shù)
Student::count(); ?//總共多少條數(shù)據(jù)
Student::where('id','>',1001)->max('age');
查看全部 -
查詢構(gòu)造器
查看全部 -
流程控制:
查看全部 -
流程控制:
查看全部 -
模板中的注釋:
{{-- 注釋的內(nèi)容 --}}
{{--? --}}中的注釋在html中看不到
查看全部 -
模板中原樣輸出 - 在輸出內(nèi)容前面加@符號
查看全部 -
模板中使用PHP代碼:
查看全部
舉報