栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

PhalAPI学习笔记拓展篇 ——— 基于MySQL数据库交互题目

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PhalAPI学习笔记拓展篇 ——— 基于MySQL数据库交互题目

PhalAPI学习笔记拓展篇 ——— 基于MySQL数据库交互题目
  • 前言
  • 约束
  • 基于MySQL数据库交互题目
    • 简单篇
      • 查询某所有的数据
      • 单查询id、project、title
      • 聚合函数返回总数量
      • 查询id为49的数据
      • 查询id为49并且title为账号管理的数据
    • 中级篇
      • 查询id为50并且title为账号列表的数据(数组方式)
      • 查询id为1或title为账号列表的title数据
      • 嵌套查询id为51并且title为添加账号
      • 嵌套查询id为51并且title为添加账号(关联性数组)
    • 高级篇
      • in方式查询id为49,50,51的数据
      • in方式查询id为49,50,51和title为账号管理、账号列表、添加账号
      • 查询title中包含 账号 的所有数据
      • 查询title中为空的所有数据
      • 倒序查询id所有数据
      • 以id为分组查询所有project字段中数据为 admin的所有数据
      • 查询10条数据
  • 答案
  • 结束语

前言

公司业务需要转学PHP,而PHP中一个功能强大且生态链完整的PHP接口框架 PhalAPI
值得大家去学习,本学习笔记持续更新!
虽然官方文档写的十分明白,以及CSDN中PhalAPI框架内容也少之又少。
因此,以自我踩坑为基础,提供一个更为精简的学习笔记,本学习笔记将会省略部分安装及简单操作。

拓展篇内容将全面直线进入强化期

约束
  • 需要满足PhalAPI框架的 ADM(API Domain Model) 模式
  • 内容需全自做,若遇到不会的题目,可在末尾找到相关答案
  • Model查询需要使用NotORM
基于MySQL数据库交互题目

自建数据库,字段需求:

简单篇 查询某所有的数据

参考语句 $this->getORM()->select()

答:………

单查询id、project、title

参考语句 $this->getORM()->select()

答:………

聚合函数返回总数量

参考语句 $this->getORM()->select()

答:………

查询id为49的数据

参考语句 $this->getORM()->where()

答:………

查询id为49并且title为账号管理的数据

参考语句 $this->getORM()->where()

答:………

中级篇 查询id为50并且title为账号列表的数据(数组方式)

参考语句 $array = array(); $this->getORM()->where($array);

答:………

查询id为1或title为账号列表的title数据

参考语句 $this->getORM()->where()

答:………

嵌套查询id为51并且title为添加账号

参考语句 $this->getORM()->where()

答:………

嵌套查询id为51并且title为添加账号(关联性数组)

参考语句 $this->getORM()->where()

答:………

高级篇 in方式查询id为49,50,51的数据

参考语句 $this->getORM()->where()

答:………

in方式查询id为49,50,51和title为账号管理、账号列表、添加账号

参考语句 $this->getORM()->where()

答:………

查询title中包含 账号 的所有数据

参考语句 $this->getORM()->where()

答:………

查询title中为空的所有数据

参考语句 $this->getORM()->where()

答:………

倒序查询id所有数据

参考语句 $this->getORM()->order()

答:………

以id为分组查询所有project字段中数据为 admin的所有数据

参考语句 $this->getORM()->group()

答:………

查询10条数据

参考语句 $this->getORM()->litmit()

答:………

答案
   

//    初级篇
    public function selectAll(){
        return $this->getORM()->select("*")->fetchAll();
    }

    public function selectByIDAndProjectAndTitle(){
        return $this->getORM()->select("id , project ,title")->fetchAll();
    }

    public function selectCount(){
//        另外ORM也封装了一个count函数
//        return $this->getORM()->count();
        return $this->getORM()->select("COUNT(*)")->fetchAll();
    }

    public function selectById(){
        return $this->getORM()->where("id = ?",49)->fetchOne();
    }

    public function selectByIdAndTitle(){
        return $this->getORM()->where("(id = ? or title = ?)",49,"账号管理")->fetchOne();
    }

//    中级篇
    public function midSelectByIdAndTitle(){
        $arr = array();
        $arr['id'] = 50;
        $arr['title = ?'] = "账号列表";
        return $this->getORM()->where($arr)->fetchOne();
    }

    public function midSelectByIdOrTitle(){

        return $this->getORM()->where("id = ?",1)->or("title = ?",'账号列表')->fetchAll();
    }

    public function midSelectByIdAndsTitle(){
        $arr = array("51","添加账号");
        return $this->getORM()->where("(id = ? OR title = ?)",$arr)->fetchOne();
    }

    public function midSelectByIdRelationAndTitle(){
        $arr = array(":id" => 51,":title","添加账号");
        return $this->getORM()->where("(id = :id OR title = :title)",$arr)->fetchOne();
    }

    //    高级篇
    public function highInSelectById(){
        $arr = array(49,50,51);
        return $this->getORM()->where("id",$arr)->fetchAll();
    }


//    in方式查询id为49,50,51和title为账号管理、账号列表、添加账号
    public function highInSelectByIdAndTitle(){
        $arr = array(array(49,"账号管理"),array(50,"账号列表"),array(51,"添加账号"));
        return $this->getORM()->where("(id,title)",$arr)->fetchAll();
    }

//    查询title中包含 账号 的所有数据
    public function highLikeTitle(){
        return $this->getORM()->where("title like ?","%账号%")->fetchAll();
    }

//    查询title中为空的所有数据
    public function highTitleNull(){
        return $this->getORM()->where("title is null")->fetchAll();
    }

    public function highDescId(){
        return $this->getORM()->order("id desc")->fetchAll();
    }

    public function highGroup(){
        return $this->getORM()->group("id","project = 'admin'")->fetchAll();
    }

    public function highLimit(){
        return $this->getORM()->limit(10)->fetchAll();
    }
    
结束语

关于 PhalAPI学习笔记拓展篇 ——— 基于MySQL数据库交互题目 就讲到这里,对你有帮助的话!

  • 点赞
  • 收藏

谢谢你的观看!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/998725.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号