ThinkPHP之数据删除和执行原生SQL语句

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yexudengzhidao/article/details/54962586

一.数据删除

delete() 返回受影响的记录条数

$goods->delete(30);//删除主键值等于30的记录信息
$goods->delete('10,12,14');//删除主键值等10,12,14的三条 记录
$goods->where('goods_id>60')->delete();//把符合条件的记录都给删除

二. 执行原生SQL语句

  1. 查询语句query() 返回一个二维数组信息
  2. 添加、修改、删除 execute() 返回受影响的记录条数
    $goods = D(“Goods”);
    $sql = “select * from sw_goods”;
    $rst = $goods -> query($sql);

$sql = “select goods_category_id,avg(goods_price) from sw_goods group by goods_category_id having avg(goods_price)>1000”;
$goods -> query($sql);

$sql = “update sw_goods set goods_name = ‘htc_two’ where goods_id=100”;
$goods -> execute($sql);

展开阅读全文

没有更多推荐了,返回首页