模型自動驗證和資料表操作

2021-10-13 13:05:01 字數 1472 閱讀 8603

(一)大多情況加運算元據表,檔名稱,類的的名稱一般對應資料表

(二)驗證欄位的合法性

案例展示:資料表user

namespace

home\model

;use

think\model

;class

usermodel

extends

model

1、特別的檔名,類名,不一定要和資料表名一致

案例展示:運算元據庫run_order,資料表shop_car

//*****

//*****檔名稱 runordertableshopcarmodel.class

//*****

<?php

namespace

home\model

;use

think\model

;class

runordertableshopcarmodel

extends

model

(一)關鍵字:$_validate

<?php

namespace

home\model

;use

think\model

;class

runordertableshopcarmodel

extends

model

else

}}

(二)使用驗證方法

1、例項化模型:d(『模型檔名稱』);

2、呼叫驗證方法:md−

>cr

eate

(字段數

據變數)

3、獲取

驗證結果

:md->create(字段資料變數) 3、獲取驗證結果:

md−>cr

eate

(字段數

據變數)

3、獲取

驗證結果

:md->geterror()

案例展示:

//******

//******模型

//******

namespace

home\model

;use

think\model

;class

runordertableshopcarmodel

extends

model

//******

//******控制器

//******

public

function

add(

)else

}$this

->

theme

('theme_blue')-

>

display()

;}

mysql種約束和資料表操作

約束 約束保證資料的完整性和一致性 約束分為表級約束和列級約束 對某乙個字段約束成為列級約束 針對兩個或兩個以上字段約束成為表級約束 約束型別包括 not null 非空約束 primary key 主鍵約束 unique key 唯一約束 default 預設約束 foreign key 外來鍵約...

MySQL資料庫和資料表操作

顯示資料庫 show databases 顯示資料表 show tables 選擇資料庫 use database name 顯示表結構 desc table name create database database name drop database database name create ...

三 資料庫操作和資料表操作

目錄 1.資料庫相關操作 2.資料表相關操作 3 表結構相關操作 1.1 建立資料庫 create db name 檢測資料庫名稱是否存在,不存在則建立 create database if not exists db name 在建立資料庫的同時指定編碼方式 create database if ...