代码:--------------------------------------------------------------------------------
//建立一个TEST表CREATE TABLE TEST ( ID NUMBER(16) NOT NULL, NAME VARCHAR2(30) NOT NULL, PRIMARY KEY (ID));
//插入一条数据INSERT INTO TEST VALUES (5, 'PHP_BOOK');
//建立一个存储过程CREATE OR REPLACE PROCEDURE PROC_TEST ( p_id IN OUT NUMBER, p_name OUT VARCHAR2) AS BEGIN SELECT NAME INTO p_name FROM TEST WHERE ID = 5;END PROC_TEST;/
--------------------------------------------------------------------------------
PHP代码:--------------------------------------------------------------------------------
<?php
//建立数据库连接$user = "scott"; //数据库用户名$password = "tiger"; //密码$conn_str = "tnsname"; //连接串(cstr : Connection_STRing)$remote = true //是否远程连接if ($remote) { $conn = OCILogon($user, $password, $conn_str);}else { $conn = OCILogon($user, $password);}
//设定绑定$id = 5; //准备用以绑定的php变量 id$name = ""; //准备用以绑定的php变量 name
/** 调用存储过程的sql语句(sql_sp : SQL_StoreProcedure) * 语法: * BEGIN 存储过程名([[:]参数]); END; * 加上冒号表示该参数是一个位置**/$sql_sp = "BEGIN PROC_TEST(:id, :name); END;";
//Parse$stmt = OCIParse($conn, $sql_sp);
//执行绑定OCIBindByName($stmt, ":id", $id, 16); //参数说明:绑定php变量$id到位置:id,并设定绑定长度16位OCIBindByName($stmt, ":name", $name, 30);
//ExecuteOCIExecute($stmt);
//结果echo "name is : $name<br>";
?>