php 存取oracle 預存程序實例詳解
例如我的本地Oracle資料庫有一個package,裡面有一個預存程序:
create or replace package PKG_TRANS_REL is -- Author : test -- Created : -- Purpose : test -- Public type declarations PKG_NAME varchar2(20) := 'PKG_TRANS_REL'; --存储过程,测试用 procedure pro_GC_withdraw(in_merch_no in varchar2, in_withdraw_amt in number, out_result out number, out_errmsg out varchar2); end PKG_TRANS_REL;
包名是PKG_TRANS_REL,存儲過程是pro_GC_withdraw
包名是PKG_TRANS_REL,存儲過程是pro_GC_withdraw,這個存儲過程有四個參數,個入參,兩個出參。 在PHP中透過pdo呼叫範例:$this->_pdo = new PDO(PDO_DB_DNS, PDO_DB_USER, PDO_DB_PASSWORD); $call = "CALL PKG_TRANS_REL.pro_GC_withdraw(?,?,?,?)"; try{ $stmt = $this->_pdo->prepare($call); $stmt->bindParam(1, $merch_no); $stmt->bindParam(2, $amount, PDO::PARAM_INT); $stmt->bindParam(3, $result, PDO::PARAM_INT, 4); $stmt->bindParam(4, $error_msg, PDO::PARAM_STR, 64); $stmt->execute(); }catch (PDOException $e) { $msg = 'SQL:'.$e->getMessage(); $msg = iconv('GBK','UTF-8',$msg); user_dump('SQL:'.$msg); return false; } ...