第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

快速入門ThinkPHP 5.0 --模型篇

難度中級(jí)
時(shí)長 3小時(shí) 0分
學(xué)習(xí)人數(shù)
綜合評(píng)分9.67
70人評(píng)價(jià) 查看評(píng)價(jià)
10.0 內(nèi)容實(shí)用
9.5 簡潔易懂
9.5 邏輯清晰
  • tp里面更新數(shù)據(jù)的兩種方式

    1.

    $model::where(array('字段'=>'值'))->update(array($change));?

    或者如圖所示;

    查看全部
  • use think\Db;

    $db = Db::name('table');

    $db->insert($data); //返回值是影響記錄的行數(shù) 插入數(shù)

    $db->insertGetId($data); //返回插入數(shù)的自增id

    $db->insertAll($data); //返回插入的成功行數(shù)

    查看全部
  • 軟刪除:

    首先在模型里面引用SoftDelete

    <?php

    namespace app\index\model;

    use think\Model;

    use traits\model\SoftDelete;

    class User extends Model{

    ? ? use SoftDelete;

    #刪除數(shù)據(jù)的時(shí)候刪除時(shí)間戳默認(rèn)寫入字段delete_time中,當(dāng)要自定義時(shí):

    // ? ?protected $deleteTime = '自定義刪除時(shí)間字段名';

    }


    然后在控制器里面執(zhí)行操作:

    ?public function index(){

    // ? ? ? ?$res = User::destroy(4);//被軟刪除

    // ? ? ? ?$res = User::get(4);//返回NULL

    ?

    ? ? ? ? #查詢包含已刪除的數(shù)據(jù)

    ? ? ? ? //$res = User::withTrashed(true)->find(2);

    ?

    ? ? ? ? #查詢僅包含已刪除的數(shù)據(jù)

    ? ? ? ? $res = User::onlyTrashed()->select();

    ? ? ? ? foreach ($res as $val){

    ? ? ? ? ? ? dump($val);

    ? ? ? ? }

    ? ? ? ? #若要恢復(fù)被軟刪除的數(shù)據(jù),直接用update方式將delete_time的值設(shè)置為NULL即可

    ?

    ? ? ? ? #當(dāng)開啟軟刪除后要想真正徹底刪除數(shù)據(jù),在destroy的第二個(gè)參數(shù)后面?zhèn)魅胍粋€(gè)true值

    ? ? ? ? $res = User::destroy(1,true);

    ?

    ? ? ? ? #通過get方式進(jìn)行軟刪除/刪除

    ? ? ? ? $res = User::get(3);//如果此處數(shù)據(jù)已經(jīng)被軟刪除則獲取到的為NULL,后面的操作無效

    ? ? ? ? $user->delete();//軟刪除

    ? ? ? ? $res = $user->delete(true);//刪除

    ? ? }


    查看全部
  • 全局添加更新時(shí)間需要在表中新建create_time和update_time字段,配置文件中設(shè)置“auto_timestamp"=>true,一般不開啟這個(gè)功能,否則表中不存在該字段時(shí)會(huì)報(bào)錯(cuò),真正刪除需要把destroy方法或delete方法的第二個(gè)參數(shù)設(shè)置為true

    123456789use?think\Model;use?traits\model\SoftDelete;class?User?extends?Model{????use?SoftDelete;使用軟刪除????protected?$autoWriteTimestamp?=?true;//開啟自動(dòng)更新時(shí)間????protected?$createTime?=?false;//設(shè)置為false代表不使用創(chuàng)建時(shí)間????protected?$updateTime?=?"update_at";//設(shè)置自定義更新時(shí)間的字段????protected?$deleteTime?=?"delete_at";//設(shè)置自定義的軟刪除字段}


    查看全部
  • auto (新增及更新的時(shí)候自動(dòng)完成的屬性數(shù)組)


    insert(僅新增的時(shí)候自動(dòng)完成的屬性數(shù)組)


    update(僅更新的時(shí)候自動(dòng)完成的屬性數(shù)組)


    查看全部
  • <?php????namespace?app\index\model;????use?think\Model;????class?User?extends?Model{????????protected?$auto?=?[????????????'time'????????];????????protected?$insert?=?[????????????'time_insert'????????];????????protected?$update?=?[????????????'time_update'????????];????????public?function?setPasswordAttr($val,$data){????????????//第二個(gè)參數(shù)是數(shù)組數(shù)據(jù)????????????return?$val.$data['email'];????????????return?md5($val);????????}????????public?function?setTimeAttr(){????????????return?time();????????}????????public?function?setTimeInsertAttr(){????????????return?time();????????}????????public?function?setTimeUpdateAttr(){????????????return?time();????????}????}

    查看全部
  • <?php????namespace?app\index\model;????use?think\Model;????class?User?extends?Model{????????public?function?getSexAttr($val){????????????switch($val){????????????????case?'1':????????????????????return?"男";????????????????????break;????????????????case?'2':????????????????????return?"女";????????????????????break;????????????????default:????????????????????return?"未知";????????????????????break;????????????}????????}????}

    查看全部
    0 采集 收起 來源:模型獲取器

    2018-11-05

  • 模型獲取器 成員方法(get字段名Attr)[字段名首字母大寫] 在model中使用 在controller中use下model中的類(該類需繼承model類),利用 ?類名::get() ?進(jìn)行獲取數(shù)據(jù)值 可利用toArray獲取改后數(shù)據(jù) 可利用getData獲取改前數(shù)據(jù)

    查看全部
    0 采集 收起 來源:模型獲取器

    2018-11-05

  • count ? ? User::count(); ? ? ? ? max ? ? ? User::max('字段名') ? sum ? ? ? User::sum('字段名') ? avg ? ? ? User::avg('字段名') ? min ? ? ? User::min('字段名') 都可以和where條件合作

    查看全部
    0 采集 收起 來源:模型聚合操作

    2018-11-05

  • destroy對(duì)數(shù)據(jù)庫刪除的操作 $userModel = User::get(7); ?$res = $userModel->delete();//對(duì)數(shù)據(jù)庫刪除的操作 $res = User::where("1=1") -> delete();//1=1 清空數(shù)據(jù)庫

    查看全部
  • <?phpnamespace?app\index\controller;use?think\Controller;use?app\index\model\User;class?Index?extends?Controller{????public?function?index(){????????#destroy返回影響行數(shù)//????????$res?=?User::destroy(function?($query){//???????????$query->where('id','<',5)//???????????????->whereOr('id','>',10)?;//????????});//????????dump($res);?????????#get返回影響行數(shù)//????????$userModel?=?User::get(7);//????????$res?=?$userModel->delete();//????????dump($res);?????????#delete,返回影響行數(shù)????????$res?=?User::where('id',10)->delete();????????dump($res);????}}

    查看全部
  • <?phpnamespace?app\index\controller;use?think\Controller;use?app\index\model\User;class?Index?extends?Controller{????public?function?index(){????????#當(dāng)數(shù)據(jù)中存在自增id時(shí),數(shù)據(jù)更新方式,返回修改的內(nèi)容,無法驗(yàn)證是否更改//????????$res?=?User::update([//????????????'id'?=>?1,//????????????'username'?=>?'wenco_update'//????????]);//????????dump($res->toArray());?????????#當(dāng)數(shù)據(jù)中不存在自增id時(shí)如下,第二個(gè)參數(shù)即為where,可以為閉包函數(shù),返回修改內(nèi)容//????????????????$res?=?User::update([//????????????'username'?=>?'wenco_update'//??當(dāng)?shù)诙€(gè)參數(shù)為數(shù)組??????],['id'?=>?'2']);//當(dāng)?shù)诙€(gè)參數(shù)為閉包函數(shù)????????],function?($query){//????????????????????$query->where('id','>=',?15);//????????????????});?????????#where?返回被影響行數(shù),推薦使用!//????????$res?=?User::where('id','between',[1,5])->update([//????????????'username'?=>?'wenco_old'//????????]);//????????dump($res);?????????#User::get,返回被影響行數(shù)//????????$userModel?=?User::get(1);//????????$userModel->username?=?'123';//????????$userModel->email?=?'123@qq.com';//????????$res?=?$userModel->save();//????????dump($res);?????????#new?User,返回影響行數(shù),第二個(gè)參數(shù)可以為閉包函數(shù)//????????$userModel?=?new?User;//????????$res?=?$userModel->save([//????????????'username'?=>?555//????????],['id'?=>??18]);//????????dump($res);?????????#saveAll,返回結(jié)果集,不推薦使用????????$userModel?=?new?User;????????$res?=?$userModel->saveAll([????????????['id'?=>?1,'username'?=>?'wencocococ'?],????????????['id'?=>?2,'username'?=>?'wencocococ'?]????????]);????????dump($res);????}}



    查看全部
  • // $res = User::create([ // 'username' => 'imooc', // 'password' => md5('imooc'), // 'email' ? ?=> 'imooc@qq.com', // 'num' ? ? ?=> 100, // 'demo' ? ? => 123 // ], ['username', 'email']); // $userModel = new User; // $userModel->username = '17771258'; // $userModel->email = '17771258@qq.com'; // $userModel->password = md5('17771258'); // $userModel->save(); // $userModel = new User; // $res = $userModel // ->allowField('username') // ->save([ // 'username' ?=> 'imooc1', // 'password' ?=> md5('imooc1'), // 'demo' ? ? ?=> 123 // ]); $userModel = new User; $res = $userModel->saveAll([ ['email'=> '17771258@qq.com'], ['email'=> '17771259@qq.com'] ]); foreach($res as $val) { dump($val->toArray()); } //dump($res); //dump($res);

    查看全部
  • Model->get 返回對(duì)象 用toarray 獲取信息

    查看全部
  • 使用模型查詢數(shù)據(jù);#通過get方式獲取數(shù)據(jù),括號(hào)內(nèi)可以為主鍵,也可以為閉包函數(shù)

    // ? ? ? ?$res = User::get(function($query){

    // ? ? ? ? ? ?$query->where("username","eq","wenco_3")

    // ? ? ? ? ? ?->field("email");

    // ? ? ? ?});

    ?

    // ? ? ? ?$res = User::where("id","<=",15)

    // ? ? ? ? ? ?->field("id,username")

    // ? ? ? ? ? ?->limit(19)

    // ? ? ? ? ? ?->order("id" ?,"DESC")

    // ? ? ? ? ? ?->select();


    查看全部

舉報(bào)

0/150
提交
取消
課程須知
1、有一定的php基礎(chǔ)。 2、對(duì)ThinkPHP5 有一定的了解。 3、沒有接觸過tp5 的學(xué)生可以先看下我之前錄制的 <快速入門 ThinkPHP5 基礎(chǔ)篇>
老師告訴你能學(xué)到什么?
1、ThinkPHP5 的數(shù)據(jù)庫操作類 2、ThinkPHP5 的數(shù)據(jù)模型 3、使用數(shù)據(jù)模型快速對(duì)數(shù)據(jù)庫進(jìn)行增刪改查的操作 4、ThinkPHP5 的自動(dòng)完成操作 5、模型的自動(dòng)時(shí)間戳和軟刪除

微信掃碼,參與3人拼團(tuán)

微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復(fù)購買,感謝您對(duì)慕課網(wǎng)的支持!