duangang79177 2013-07-01 01:08
浏览 18
已采纳

链接MySQL命令。 原始查询

I have been building a lot of website in the past using my own cms/framework and I have developed a simple way of executing queries. Recently I have started playing with other frameworks such as code igniter. They offer raw query imputs such as…

$this->db->query(“SELECT * FROM news WHERE newsId=1;”);

But they also offer chaining of MySQL command via PHP methods.

$this->db->select("*")->from("news")->where("newsId=?");

The question is; what is the main difference and of benefits of each option.

I know the latter options prevents MySQL injection but to be honest you can do exactly the same from using $this->db->escape().

So in the end from what I can see the latter option only serves to make you use more letters on your keyboard, this you would think would slow you down.

  • 写回答

3条回答 默认 最新

  • doumeng1897 2013-07-01 02:58
    关注

    Most recent php framework developers are uses AR(active record)/DAO(database access object) Pattern. Because it's really faster then raw query. Nowadays AR technique originally built from PDO(php data object).

    why active record is really faseter?

    its true query writing is the best habit for a developer. But some problem make it tough

    1. When we write insert and update large query, sometime it's hard to match every row value.. but AR make it easy. you just add array first and then execute easily.
    2. Doesn't matter what DB you use.
    3. Sometimes it's really hard read or write query if it has many condition. But in AR you can cascade many object for 1 query.
    4. AR save your time to repeating statement

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用