How to call a MySQL stored procedure(with parameter) in Yii ?

How to call a MySQL stored procedure(with parameter) in Yii using any of Active Record, Query Builder or DAO ?

Let’s assume your stored procedure is call my_proc and accepts one argument - “echome”.


$command = Yii::app()->db->createCommand('call my_proc("nice day today")');

$command->execute();

hey, this looks great ! Does this also work with postgresql functions ?

I have no idea how stored procedures work in postgresql. You can execute any kind of sql as long as the syntax is correct.

For postgresSQL you need to do




$command = Yii::app()->db->createCommand('SELECT * FROM stored_function(parameters);');

        

print_r($command->queryRow());



where stored_function is the function name, and parameters are what you are going to send to the database.