码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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()

    答:………

    答案

       /**
         *  csdn PhalAPI 数据库交互答案
         *  @Author Marinda
         */
    
    //    初级篇
        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();
        }
        
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86

    结束语

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

    • 点赞
    • 收藏

    谢谢你的观看!

  • 相关阅读:
    close excel by keyword 根据关键字关闭 excel 窗口 xlwings 方式实现
    低代码平台全解析:衍生历程、优势呈现与未来趋势一览无余
    MySQL数据库之MHA高可用
    css大屏动画效果
    基于云计算与深度学习的常见作物害虫识别系统的设计与实现
    【Vue3】中ref如何获取dom元素,以element-plus中的走马灯next、prev方法为例
    Qt listWidget 详细分析
    小程序canvas层级过高真机遮挡组件的解决办法
    java项目实现发送邮箱激活用户功能
    Java锁小记
  • 原文地址:https://blog.csdn.net/qq_33638188/article/details/125517531
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号