Home > Backend Development > PHP Tutorial > Detailed graphic explanation of php accessing oracle stored procedures

Detailed graphic explanation of php accessing oracle stored procedures

墨辰丷
Release: 2023-03-28 08:50:02
Original
1975 people have browsed it

This article mainly introduces relevant information on PHP access to Oracle stored procedure examples. Here is the example code to help you realize such a function. Friends in need can refer to

php access Detailed explanation of oracle stored procedure examples

For example, my local Oracle database has a package, which contains a stored procedure:

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

Package The 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

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

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

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

Simple methods and encapsulated class examples for operating Oracle databases in Python

Detailed explanation of Python using cx_Oracle module to operate Oracle database

php connection to Oracle configuration under windows

The above is the detailed content of Detailed graphic explanation of php accessing oracle stored procedures. For more information, please follow other related articles on the PHP Chinese website!

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