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