PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, December 5, 2022

[FIXED] How to execute a stored procedure using OCI8 in PHP

 December 05, 2022     oci8, oracle, php, stored-procedures     No comments   

Issue

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


Solution

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);


Answered By - S.Visser
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing