how do you use Yii store procedure with MySQL

function, mysql, php, stored-procedures, yii

Solution

- Do not insert `$page` and `$section` directly into sql code. Your site will be vulnerable to SQL injections! Use params instead.

You can run a stored procedure just like you execute a normal query:

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

Problem

I need to change this function ``` public function getScripts($page, $section){ $data = Yii::app()->db->createCommand() ->select('*') ->from('scripts') ->where("page_id='$page' and section_id='$section'") ->queryAll(); return $data; } ``` into a store procedure in MySQL. How would I do this inside Yii for MySQL.

Original source