「PHP」Oracleストアドプロシージャを実行する
1.bookgitemtblの作成
create table bookgitemtbl (
id number(16) not null,
name varchar2(30) not null,
primary key (id)
);
//insert
insert into bookgitemtbl values (5, 'java_book’);
//procedure
create or replace procedure proc_edo (
p_id in out number,
p_name out varchar2
) as
begin
select name into p_name
from bookgitemtbl
where id = 12;
end proc_edo;
2.phpでプロシージャーの呼び出し
<?php
$user = “dbuser";
$password = “123456";
$conn_str = “tnsname";
$remote = true
if ($remote) {
$conn = ocilogon($user, $password, $conn_str);
}
else {
$conn = ocilogon($user, $password);
}
$id = 12;
$name = “";
$sql_sp = “begin proc_edo(:id, :name); end;";
//parse
$stmt = ociparse($conn, $sql_sp);
//bind
ocibindbyname($stmt, “:id", $id, 16);
ocibindbyname($stmt, “:name", $name, 30);
//execute
ociexecute($stmt);
echo “名前 : $name<br>";
?>