doufeng2877 2012-10-30 07:44
浏览 10
已采纳

YII中的数据库方法

I am developing my first YII website. I have a couple of doubts about YII database.

There are three methods to query database in yii.

  • Database Access Objects
  • Query Builder
  • Active Record

  1. Out of these three methods which is the secure and most preferred method?
  2. If I have custom queries to perform which method should I prefer?
  3. In case of Query Builder queries we explicitly choose table like

        $user = Yii::app()->db->createCommand()
            ->select('id, username, profile')
            ->from('tbl_user') // explicitly choosing the table
            ->join('tbl_profile p', 'u.id=p.user_id')
            ->where('id=:id', array(':id'=>$id))
            ->queryRow();
    

    so where should I write query builder queries? Is there any advantage if I write them in corresponding table model?

  4. If I use DAO or query builder what class should extend my model?

  5. How to validate user inputs if I follow DAO method or query builder method?

  • 写回答

2条回答 默认 最新

  • donglu1973 2012-10-30 08:21
    关注
    1. Depends. All are equally secured if you know how to use them securely.

    2. DAO. That's my opinion though.

    3. In the models.

    4. There are two main model classes in Yii. CFormModel and CModel. For queries, extend the class with respect to CModel.

    Just a note at the end. DAO is the fastest among them. Active record is slowest. On the other hand, active record is more convenient. You are the one who needs to decide what should be the balance.

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图