標籤:
造對象
1.原始方式(必須做模型檔案,即使是空的也要建)
$model=new \Home\Model\InfoModel();var_dump ($model);
2.D()方法(不需要建模型檔案)
//$名=D("表名");$model=D("Info");var_dump ($model);
3.M()方法(不需要建模型檔案)
//$名=M("表名");$nation=M("Nation");var_dump($nation);
操作資料庫
1.調用select方法查詢所有資料
$ainfo=$model->select();
2.調用select方根據主索引值找多條資料
$ainfo=$model->select("p001,p002,p003");
3.調用find方法根據主索引值找一條特定的資料
$ainfo=$model->find("p001");
連貫操作
where 給查詢添加條件
$ainfo=$model->where("code=‘p003‘ or sex=true")->select();
table 切換操作的表
$ainfo=$model->table("nation")->select();
alaias 設定表的別名
$ainfo=$model->alaias("人員")->select();
field 指定查詢的列
$ainfo=$model->field("code,name")->select();
order 對查詢結果排序
$ainfo=$model->order("nation desc")->select();
group 分組
$ainfo=$model->field("nation")->group("nation")->select();
having 加分組後的條件
$ainfo=$model->group("nation")->having("count(*)>2")->select();
join 串連多個表(注意:給重名的列加別名)
$ainfo=$model->field("info.code,info.name as xingming,sex,nation.name,birthday")->join("nation on info.nation = nation.code")->select();
PHP TP模型