CodeIgniter MySQL Stored Procedure and Function

MySQL has procedure and function feature. There is good article explaining both topics in http://bit.ly/dWDh9w.

To call mysql function from codeigniter, we can simply use query() function from database class. For example

$query = $this->db->query("call storedFunction($param1, $param2) as A");
$row = $query->row();
echo $row->A;

Where storedFunction is the name of function we have created before.

To call mysql stored procedure from codeigniter, we can use query() function from database class. For example

$query = "CALL hello('Chandra', @a)";
$res = $this->db->query($query);
$query = "SELECT @a as A";
$res = $this->db->query($query);
$row = $res->row();

Where hello is the name of stored procedure.

Hope this article helps 🙂


Posted

in

by

Comments

6 responses to “CodeIgniter MySQL Stored Procedure and Function”

  1. Alex Avatar

    Thank`s a lot.

  2. Yang Avatar

    it really helped thanks 🙂

  3. Peter Makenzi Avatar
    Peter Makenzi

    incase of ODBC connection use the following code to call the stored procedure:
    $query=$this->db->query(“{call usp_Students}”);
    return $query->result();

  4. chandra Avatar
    chandra

    Thanks for the information. Will try that later

  5. Csaba Toth Avatar
    Csaba Toth

    Hi, any idea how to call from Codeigniter a MYSQL stored procedure that produces multiple record sets? (for example a procedure that executes 10 separate SELECT queries and produces 10 separate recordsets)? I get back only the record set of the first SELECT statement of the procedure. I checked dozens of articles on the net so far nothing works. Thanks for any help!

  6. arun Avatar
    arun

    Error Number: 2014

    Commands out of sync; you can’t run this command now

    I am getting this error

Leave a Reply

Your email address will not be published. Required fields are marked *