ThinkPHP 5.0? ?? ?? ????? ????? MVC ??? ??? ???? ?? ?? ?? ?? PHP ??????, ???? ???? ?? ?? ??? ????? ??? ?? ???? ?????. ?? ???? ThinkPHP 5.0? ????? ??????? ???? ??, ??, ??, ???? ?? ??? ??? ??? ????.
?? ??
ThinkPHP 5.0?? ??? ??? ?? ??? ??? ????.
Db::name('table')->where('condition')->delete();
? ? Db::name('table')
? ??? ??? ?????. where('condition')
? ??? ?? ??? ????, delete()
? ?? ?? ??? ?????. Db::name('table')
指定要操作的數(shù)據(jù)表名,where('condition')
指定刪除數(shù)據(jù)的條件,delete()
表示執(zhí)行刪除操作。
刪除指定 ID 的數(shù)據(jù)
如果要刪除數(shù)據(jù)庫中指定 ID 的數(shù)據(jù),可以按照如下方式進行操作:
Db::name('table')->delete(1);
其中,1
表示要刪除的數(shù)據(jù)的 ID 號。
刪除符合條件的數(shù)據(jù)
如果要刪除符合條件的多條數(shù)據(jù),則可以使用 where
條件構(gòu)建刪除語句。例如,要刪除數(shù)據(jù)庫中所有 status
值為 0
的數(shù)據(jù),可以這樣寫:
Db::name('table')->where('status', 0)->delete();
以上語句將刪除數(shù)據(jù)表 table
中所有 status
值為 0
的數(shù)據(jù)。
刪除多條數(shù)據(jù)
在 ThinkPHP 5.0 中,可以同時刪除多條符合指定條件的數(shù)據(jù)。例如,要刪除 status
值為 0
并且 score
值小于 60
的數(shù)據(jù),可以這樣寫:
Db::name('table')->where('status', 0)->where('score', '<', 60)->delete();
以上語句將刪除數(shù)據(jù)表 table
中所有 status
值為 0
并且 score
值小于 60
的數(shù)據(jù)。
刪除所有數(shù)據(jù)
如果要刪除數(shù)據(jù)表中的所有數(shù)據(jù),可以使用以下 SQL 語句:
truncate table table;
在 ThinkPHP 5.0 中,也可以使用以下代碼進行操作:
Db::name('table')->truncate();
注意:truncate()
方法并不支持帶有條件的刪除操作,僅僅用于刪除數(shù)據(jù)表中的所有數(shù)據(jù)。
刪除相關(guān)操作
在刪除數(shù)據(jù)時,我們經(jīng)常需要考慮一些相關(guān)的操作,例如,同時刪除關(guān)聯(lián)表中的數(shù)據(jù),或者刪除相關(guān)的文件等。在 ThinkPHP 5.0 中,可以使用鉤子函數(shù) after_delete()
來進行相關(guān)操作。例如,刪除數(shù)據(jù)時刪除對應(yīng)的磁盤文件,可以這樣寫:
use think\Model; class User extends Model { protected static function afterDelete($user) { // 刪除磁盤文件 unlink('/path/to/file/' . $user['avatar']); } }
以上代碼表示在刪除數(shù)據(jù)時,會觸發(fā) after_delete()
- ????? ID? ??? ?????????????????? ??? ID? ???? ???? ??? ??? ?? ??? ??rrreee?????
1
? ??? ???? ID ??? ?????. ??- ??????? ?? ??? ????????????? ?? ?? ???? ?????
? ?????. where
???? ?? ?? ?????. ?? ?? status
?? 0
? ??????? ?? ???? ????? ??? ?? ??? ? ????. ??rrreee??? ???? ???? ???? ?????. table table
status
?? 0
? ?? ??????. ??- ?????? ??? ??????????ThinkPHP 5.0??? ??? ??? ???? ?? ???? ??? ??? ? ????. ?? ??,
status
?? 0
?? score
?? 60
?? ?? ???? ????? ??? ?? ??? ? ????. ??rrreee ??? ???? ??? ??? table
?? 0
?? ??
?? ?? ?????. >score ?? 60
????? ????. ??- ?????? ??? ????????????? ???? ?? ???? ????? ?? SQL ?? ???? ???. ??rrreee ??ThinkPHP 5.0??? ?? ??? ???? ??? ?? ????. ??rrreee????:
truncate()
???? ??? ?? ??? ???? ??? ??? ???? ?? ???? ???? ?? ?????. . ??- ?????? ?? ?????????????? ??? ? ?? ???? ??? ??? ?? ?? ?? ??? ???? ?? ??? ????. ??? ?? ?? ??? ???? ?? ??? ?????. ThinkPHP 5.0??? ?? ??
after_delete()
? ???? ?? ??? ??? ? ????. ?? ?? ??? ?? ? ?? ??? ??? ????? ??? ?? ???? ???. ??rrreee??? ??? ??? ?? ? after_delete()
?? ??? ???? ????? ?????. ???? ?????. ??? ??? thinkphp5?? ???? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

ThinkPHP ????? ????? ??? ?????: Composer? ????, ???? ????? ???? php bin/console? ????, ?? ???? ??? http://localhost:8000? ?????.

ThinkPHP?? ??? PHP ????? ??? ?? ??? ????. ??? ???? 3.2, 5.0, 5.1, 6.0? ????, ??? ??? ??? ???? ??? ??? ???? ? ?????. ?? ?? ??? ThinkPHP 6.0.16???. ??? ??? ? PHP ??, ?? ?? ?? ? ???? ??? ??????. ??? ??? ??? ???? ?? ?? ??? ???? ?? ????.

ThinkPHP Framework? ???? ???? ??: ThinkPHP Framework? ?? ????? ?????? ??? ???. ThinkPHP ?? ????? ???? ?? ???(?? ??)? ????. ?????? ?? ????? ?????. ? ??? ?????. ThinkPHP ??????? ??????. ThinkPHP ?????? URL? ???? ?????.

Laravel? ThinkPHP ?????? ?? ??: ThinkPHP? ????? ??? ? ??? ??? ?? Laravel?? ??? ????. Laravel? ? ????? ??? ??????? ?? ThinkPHP? ? ??? ? ????.

ThinkPHP ?? ??: PHP, Composer ? MySQL ??? ?????. Composer? ???? ????? ????. ThinkPHP ?????? ???? ?????. ?????? ??? ?????. ?????? ??? ?????. ??????? ???? http://localhost:8000? ?????.

ThinkPHP? ?? ????, ?? ???, ?? ?? ? ?????? ???? ?? ??? ?? ??? PHP ????????. ?? ?? ???? ??? ?? 10,000? ??? ??? ??? ? ??? JD.com, Ctrip? ?? ??? ? ??? ? ?????? ????? ?? ?? ?????? ?? ?????.

?? ??: API ??? ?? ThinkPHP ?????? ???? ?? ???? ????? ????? API(?? ????? ?????)? ???? ?? ? ??? ????. API? ??? ??, ?? ?? ? ?? ??? ??? ? ??? ????? ??? ???? ?? ?? ??? ?????. ??? PHP ?? ?????? ThinkPHP ?????? ????? ?? ???? ???? ????.

"?? ??: ThinkPHP ?????? ???? ??? ??? ???? ??" ??? ??? ??? ???? ?? ? ?? ????? ?? ?? ?? ??? ??? ???? ??? ???? ?? ?? ??? ?? ? ??????. ??? ??? ??? ??? ????? ?? ???? ??? ???, ?? ??? ??, ??? ?? ?? ?? ??? ?? ??? ??? ???? ?? ??? ??? ???? ?? ?? ?????. PHP ???? ?? ???? ?? ?????? ThinkPHP ?????? ??? ??? ???? ? ?? ??? ??? ?????.
