php编写查询或的语句,thinkphp中的查询语句

namespace AdminController;useThinkController;class MainController extendsController

{public functionshowList()

{echo "大苹果商城";

}public functiontest()

{//数据访问

//造模型对象

//$nation = D("Nation");//连接数据库中的Nation表

//查询

//$a = $nation->select();//查询所有,返回关联数组,也是二维数组。

//$a = $nation->select("n001,n002,n003");//通过主键值查,注意写法。

//$a = $nation->find();//查一条数据,返回一维数组。

//$a = $nation->find("n001");//按照条件查询

//$a = $nation->where("name='汉族'or name='回族'")->select();//where()只能写查询条件。select才会输出,select返回的是二维数组。这种操作称为连贯操作

//$a = $nation->table("info")->select();//table切换其它表格查询表格信息。上面虽然是链接的Nation表,这里切换到info表格。

//$a = $nation->field("code")->select();//查询指定字段,这里查询的是code列,多个字段中间用,分隔。

//$a = $nation->order("code desc")->select();//code按照降序排列

//$a = $nation->limit(3)->select();//查询前3条数据,limit分页查询。

//$a = $nation->limit(3,4)->select();//跳过3条显示4条

//$a = $nation->page(2,3)->select();//page中第一个参数是第几页,第二个参数是几条数据。这里是取第2页的3条数据。

//$a = $nation->table("car")->field("Brand,avg(price)")->group("brand")->select();//分组查询

//$a = $nation->table("car")->field("Brand,avg(price)")->group("brand")->having("avg(price)>50")->select();//having条件查询

//$a = $nation->field("Info.code,Info.name as 'name',nation.name as '民族'")->join("Info on Nation.code=Info.Nation")->select();//用join连接的时候前面的field的列要加上别名,不然会出问题。

//$a = $nation->table("car")->distinct(true)->field("brand")->select();//distinct去重

//$a = $nation->where("code='n003'")->getField("name");//只能写列名,获取某一列的值。

//$a = $nation->count();//也可以放在连贯操作的最后用,求出数据量。

//$a = $nation->table("car")->max("price");

//使用原生的查询方法

//$sql = "select * from nation";

//$a = $nation->query($sql);//查询语句还是按照原来的调用方法。

//$sql = "update nation set name='矮人族' where code='n001'";

//$a = $nation->execute($sql);//增、删、改语句用execute调用。

//var_dump($a);

}

}?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值