【问题标题】:how do you use Yii store procedure with MySQL你如何在 MySQL 中使用 Yii 存储过程
【发布时间】:2012-11-14 06:39:27
【问题描述】:

我需要改变这个功能

    public function getScripts($page, $section){
        $data = Yii::app()->db->createCommand()
                ->select('*')
                ->from('scripts')
                ->where("page_id='$page' and section_id='$section'")
                ->queryAll();
        return $data;
    }

进入 MySQL 中的存储过程。我将如何在 Yii for MySQL 中执行此操作。

【问题讨论】:

标签: php mysql function stored-procedures yii


【解决方案1】:
  1. 不要将$page$section直接插入到sql代码中。您的网站将容易受到 SQL 注入的攻击!请改用参数。
  2. 您可以像执行普通查询一样运行存储过程:

    public function getScripts($page, $section){
        return Yii::app()->db->createCommand("CALL your_stored_procedure(:page, :section)")
                          ->queryAll(array(':page' => $page, ':section' => $section));
    }
    

【讨论】:

  • 如果我有两个查询,那么我应该如何检索结果?
  • 我找到了解决方案here
猜你喜欢
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
  • 1970-01-01
  • 2016-06-27
  • 2012-06-15
  • 2010-09-16
  • 2018-08-29
  • 1970-01-01
相关资源
最近更新 更多