Detailed explanation of PHP access to Oracle stored procedure instance

高洛峰
Release: 2023-03-04 18:00:02
Original
1078 people have browsed it

php Detailed explanation of accessing oracle stored procedure instances

For example, my local Oracle database has a package with a stored procedure in it:

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;
Copy after login

The package name is PKG_TRANS_REL, and the stored procedure is pro_GC_withdraw. This stored procedure has four parameters, two input parameters and two output parameters.

Example of calling via pdo in PHP:

$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;
  }
 
  ...
Copy after login

The third parameter of bindParam defaults to PDO::PARAM_STR, if it is other types To specify

It is relatively simple to pass the value of the incoming parameter, but it is slightly more complicated to pass the outgoing parameter, and the length must be specified.

For more php access to oracle stored procedure examples, please pay attention to the PHP Chinese website for related articles!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!