Calling Oracle Stored Procedures with PHP
Hello !
I am a new guy, learning PHP and need to know the functionality of PHP with oracle where as I am so far from oracle but I get more enjoyed with oracle and willing to work with oracle database as a back end for my PHP applications. recently, I need to know about,how I would call particular procedure from the PHP code.
Your help would appreciated more...Thank you very much.
Stored Procedure Input and Output with PHP
Stored Procedure Input and Output :
When you make a call to the procedure,all input and output data is passed as arguments to the procedure.This may be doubtful at first,if you will use the semantics of calling a PHP function with some arguments which returns a value as example shows :
Quote:
Computer_data (Order_count IN NUMBER, Values_Rs. OUT NUMBER)
When you call this procedure,the first argument Order_count would contain an input value which you pass during call and Values_Rs would be used as a return specifier attribute by the procedure upon the completion of procedure operation.
Calling Stored Procedures from PHP
Calling Stored Procedures from PHP :
According to the behavior of SQL statement,you use the statement under PHP codes and make a call to the procedure.You will nest the calls between the BEGIN ... END block which is also known as Anonymous block.
Like :
<?php
// etc.
$sql = 'BEGIN Computer_data(:Order_count, :Values_Rs); END;';
This statement will bind the variables with the PHP variables with calls to oci_bind_by_name().
If the sayHello procedure was defined by the following DDL statement:
Code:
CREATE OR REPLACE PROCEDURE
Computer_data (order_count IN INTEGER, Values_Rs OUT INTEGER)
AS
BEGIN
Values_Rs := 2,12000 || Order_count;
END;
/
Calling Oracle Stored Procedures with PHP
Run the created script with the SQL*Plus command line and save the executed statement in the file with the identification name and login again.
$ sqlplus username@SID
Now create the procedure with the START command with the name of file :
SQL> START /home/username/Comp_pro.SQL
Containing the codes to call Stored Procedures within PHP
Codes to call Stored Procedures within PHP :
You need to use the following script to call the procedure within PHP :
Quote:
<?php
$conn = oci_connect('HR','HR') or die;
$sql = 'BEGIN Computer_data(:Order_count, :Values_Rs); END;';
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,':Order_count',$Order_count,32);
oci_bind_by_name($stmt,':Values_Rs',$Values_Rs,32);
$Order_count = 24;
oci_execute($stmt);
print "$......The Values would be following...\n";
?>