search
Homephp教程php手册ThinkPHP执行Oracle存储过程

ThinkPHP+Oracle执行存储过程。
一、首先修改ThinkPHP3.0的Oracle驱动(ThinkPHP\Lib\Driver\Db\DbOracle.class.php),在DbOracle类中增加以下方法:    /**<br>      +----------------------------------------------------------<br>      * 执行存储过程<br>      +----------------------------------------------------------<br>      * @author   hongping <hongping626><br>      +----------------------------------------------------------<br>      * @param  string $pName  存储过程名称  <br>      * @param  array  $pValue 传入参数值<br>      +----------------------------------------------------------<br>      * @return array  返回执行结果<br>      +----------------------------------------------------------<br>      */<br>      public function execProcedure($pName,$pValue) {<br>         $pValue = array_change_key_case($pValue, CASE_LOWER);//强制下标为小写<br>         $this->initConnect(true);<br>         if ( !$this->_linkID ) return false;<br>         //更改事务模式<br>         $this->mode = OCI_COMMIT_ON_SUCCESS;<br>         //释放前次的查询结果<br>         if ( $this->queryID ) $this->free();<br>         N('db_write',1);<br>         // 记录开始执行时间<br>         G('queryStartTime');        <br>         $argSql = "SELECT ARGUMENT_NAME,IN_OUT FROM USER_ARGUMENTS WHERE OBJECT_NAME = '".strtoupper($pName)."' ORDER BY SEQUENCE";        <br>         $argRow = $this->query($argSql);<br>         $ParStr = '';<br>         $x = 0;   <br>         foreach($argRow as $key=>$value){<br>                 if($x==0){<br>                     $ParStr .= ":".$value['argument_name'];                    <br>                 }else{<br>                     $ParStr .= ",:".$value['argument_name'];                    <br>                 }<br>                 $x++;<br>         }<br>         $this->queryID = oci_parse($this->_linkID, 'BEGIN '.$pName.'('.$ParStr.');END;');<br>         foreach($argRow as $key=>$value){<br>           $parmName = strtolower($value['argument_name']);<br>           $parmType = strtolower($value['in_out']);<br>           if($parmType==='out'){<br>             oci_bind_by_name($this->queryID, ":".$parmName, $OutData[$parmName],2048);<br>           }else{<br>             $OutData[$parmName] = $pValue[$parmName];<br>             oci_bind_by_name($this->queryID, ":".$parmName, $OutData[$parmName],2048);<br>           }<br>         }         <br>         oci_execute($this->queryID);             <br>         $this->debug();<br>         if (!$this->queryID) {<br>             $this->error();<br>             return $this->queryID;<br>         }else {<br>             return $OutData;<br>         }<br>     }</hongping626>二、然后在ThinkPHP\Lib\Core\Model.class.php加入以下(1185行左右):/** <br>      +---------------------------------------------------------- <br>      * 执行oracle存儲過程 <br>      +---------------------------------------------------------- <br>      * @access public <br>      +---------------------------------------------------------- <br>      * @param string  $sql    SQL指令 <br>      * @param array   $parr   传入传出参数值 <br>      * @param boolean $parse  是否需要解析SQL <br>      +---------------------------------------------------------- <br>      * @return false | integer <br>      +---------------------------------------------------------- <br>      */  <br>     public function execProcedure($sql,$parr,$parse=false) {  <br>         $sql  =   $this->parseSql($sql,$parse);  <br>         return $this->db->execProcedure($sql,$parr);  <br>     } 使用示例:public function testPub(){            <br>          $data['name'] =  $_POST['name']; //存储过程传入参数<br>          $data['value'] =   $_POST['value']; //存储过程传入参数<br>            <br>          $pdName = "PUB_TEST_KT";/*存储过程名*/  <br>          $result =M() ->execProcedure($pubName,$pubParm);//执行<br>          $this->success($result['res']);//返回结果

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.