How to execute a stored procedure using OCI8 in PHP

user2234937 picture user2234937 · Apr 16, 2013 · Viewed 15.7k times · Source

Can someone help me on how to call the stored procedure in oracle by php? I have the sample of stored procedure

CREATE OR REPLACE PROCEDURE view_institution(
       c_dbuser OUT SYS_REFCURSOR)
IS
BEGIN
  OPEN c_dbuser FOR
  SELECT * FROM institution;
END;

the above stored procedure named view_instituion used to display all record on table institution. Can someone teach me to call the above stored procedure in php. Im new on playing with stored procedure

thanks

Answer

S.Visser picture S.Visser · Apr 16, 2013

If you use the PDO engine

/* Define output */
$output = "";    

/* The call */
$stmt= $pdo->prepare("CALL view_institution(?)");

/* Binding Parameters */
$stmt->bindParam($parameter1, $output);
 
/* Execture Query */
$stmt->execute();

/* Get output on the screeen */
print_r($output, true);

If you use oci

/* The call */
$sql = "CALL view_institution(:parameter)";

/* Parse connection and sql */
$stmt= oci_parse($conn, $sql);
 
/* Binding Parameters */
oci_bind_by_name($stmt, ':parameter', $yourparameter) ;

/* Execute */
$res = oci_execute($stmt);

/* Get the output on the screen */
print_r($res, true);