Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling stored procedure from codeigniter

I am using codeigniter that has mysqli as db driver, am trying to call a simple stored procedure from my model but get an error. What am i doing wrong

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pc()' at line 1

pc()

Filename: C:\hosted\saner.gy\ipa\system\database\DB_driver.php

Line Number: 330

When i run the query call Stored Procedure it runs well but from codeigniter it throws the above error

Stored Procedure

CREATE DEFINER=`root`@`localhost` PROCEDURE `pc`()
    LANGUAGE SQL
    NOT DETERMINISTIC
    CONTAINS SQL
    SQL SECURITY DEFINER
    COMMENT ''
BEGIN
    SELECT * FROM tbl_flo
  WHERE name = 'sam';
END

Controller

public function sp()
{
$this->User_model->pc();
}

Model

public function pc()
        {
            $query = $this->db->query("pc()");

            return $query->result();
        }
like image 767
Samuel Masinde Avatar asked Aug 18 '15 08:08

Samuel Masinde


1 Answers

Stored procedures are invoked using the CALL procedure_name(optional_params) query.

You need to edit the query used in your model like this:

public function pc()
    {
        $query = $this->db->query("CALL pc()");
        return $query->result();
    }
like image 135
ROAL Avatar answered Sep 29 '22 21:09

ROAL