How to call a stored procedure in CodeIgniter?

I cannot call a stored procedure in CodeIgniter. However, when I call the procedure directly in MySQL, it works. Why doesn't it work when I call it in CodeIgniter?

CREATE DEFINER=`root`@`localhost` PROCEDURE `test_proc`() LANGUAGE SQL NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER COMMENT '' BEGIN declare name1 TEXT; declare id1 TEXT; select name,id into name1,id1 from my_tbl WHERE name='sam'; select * from my_tbl; select name1,id1; END 
+8
php mysql stored-procedures codeigniter
source share
2 answers

I think you are using the following method of calling a procedure.

 $this->db->call_function('test_proc'); 

Wrong. With this method, only the default procedures can be called. To call the procedures you have defined, you must go with

 $this->db->query("call test_proc()"); 
+19
source share

For Oracle procedures, here is an easy way to call

  $rsponse = ''; $s = oci_parse($this->db->conn_id, "begin packageName.procedureName(:bind1,:bind2,:bind3,:bind4,:bind5); end;"); oci_bind_by_name($s, ":bind1", $data['fieldOne'],300); oci_bind_by_name($s, ":bind2", $data['fieldTwo'],300); oci_bind_by_name($s, ":bind3", $data['fieldThre'],300); oci_bind_by_name($s, ":bind4", $data['fieldFour'],300); oci_bind_by_name($s, ":bind4", $response,300); oci_execute($s, OCI_DEFAULT); echo $message; 

In the above procedure, the procedure takes four arguments as input and one parameter as output. in case of direct call procedure, delete 'packageName.' What is it...

+2
source share

All Articles