Calling Oracle stored procedure in PHP

June 20th, 2007

Okay, in this post we will discuss about PHP again. After connecting to Oracle, we can do some query here. Data Manipulation Language (DML) is the basic of SQL (Structured Query Language). But, what about DML in stored procedure? We will create it! Before continuing, we must create table first. Just make a simple table. Here is the SQL code: create table mytable(id number (3) not null,name varchar2 (25) not null,address varchar2 (25) ,constraint pk_mytable primary key (id)); First, create insert procedure to the table. The parameters are the field we want to insert. create or replace procedure insert_mytable (pid, pname, paddress)begininsert into my_table (id, name, address) values (pid, pname, paddress);end;Second, create update procedure to update the record of the table. It’s still using the same parameters.create or replace procedure update_mytable (pid, pname, paddress)beginupdate my_table set id=pid, pname=name, paddress=adress where id=pid;end; The last is creating delete procedure. It is used to delete the data from the table. But, we only need one parameter here. create or replace procedure delete_mytable (pid)begindelete from my_table where id=pid;end; The next step is calling procedures we’ve created in PHP. Input parameter we can get from a form in html view.//connect to Oracleinclude(“connection.php”);//get input$id = $_POST['id'];$name = $_POST['name'];$address = $_POST['address'];//call stored procedured$query = “BEGIN insert_mytable (:id, :name, :address); END;”;//parse the query$s = ociparse($c, $query);//bindingocibindbyname($s, ‘:id’, $id, 32 );ocibindbyname($s, ‘:name’, $name, 32 );ocibindbyname($s, ‘:address’, $address, 32 );//execute the queryociexecute($s); Before calling the stored procedure, we must connect to Oracle first. It’s done with including connection.php (connection to Oracle has written in the last post). Get the input parameter and then call it. Don’t forget to parse and bind it. And the last step is executing the query. Okay, send me a email if you want to ask about this. Thanks…Read more at: Knowledge to Share (http://studiawan.blogspot.com/2007/06/calling-oracle-stored-procedure-in-php.html)


Author: Gautam Categories: Uncategorized Tags:
  1. January 1st, 2008 at 16:54 | #1

    Enlightening article.. thanks bro :D

    RobertGarcia’s last blog post..Star Trek XI (2008)

  1. No trackbacks yet.