PHP--TP框架----操作数据库

时间:2023-02-12 14:43:37

//操作数据库

                   //$attr = $m->select(); //查询所有数据

                   //$attr = $m->select("p001,p002,p003");

                   //$attr = $m->find("p001"); //找特定的数据根据主键值找

                  

                   //where可以加查询条件

                   //$attr = $m->where("code='p001' or sex=true")->select();

                  

                   //table可以切换要操作的表

                   //$attr = $m->table("Nation")->select();

                  

                   //alias可以设置表的别名

                   //$attr = $m->alias("人员")->select();

                  

                   //field可以指定查询的字段

                   //$attr = $m->field("code,name")->select();

                  

                   //order可以加排序条件

                   //$attr = $m->order("Nation desc")->select();

                  

                   //group可以分组

                   //$attr = $m->field("Nation")->group("Nation")->select();

                  

                   //having可以加分组后的条件

                   //$attr = $m->field("Nation")->group("Nation")->having("count(*)>5")->select();

                  

                   //join可以连接多个表,在field里面要给字段加别名

                   $attr = $m->field("Info.Code as 代号,Info.Name as 姓名,Sex as 性别,Nation.Name as 民族名称")->join("Nation on Info.Nation = Nation.Code")->select();

                  

                  

                   var_dump($attr);

                  

                  

         }