BVB Source Codes

The latest thinkphp v5.2 work order system Show Oracle.class.php Source code

Return Download The latest thinkphp v5.2 work order system: download Oracle.class.php Source code - Download The latest thinkphp v5.2 work order system Source code - Type:.php
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11.  
  12. namespace Think\Db\Driver;
  13. use Think\Db\Driver;
  14.  
  15. /**
  16.  * Oracle数据库驱动
  17.  */
  18. class Oracle extends Driver{
  19.  
  20.     private     $table        = '';
  21.     protected   $selectSql    = 'SELECT * FROM (SELECT thinkphp.*, rownum AS numrow FROM (SELECT  %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%) thinkphp ) %LIMIT%%COMMENT%';
  22.  
  23.     /**
  24.      * 解析pdo连接的dsn信息
  25.      * @access public
  26.      * @param array $config 连接信息
  27.      * @return string
  28.      */
  29.     protected function parseDsn($config){
  30.         $dsn  =   'oci:dbname=//'.$config['hostname'].($config['hostport']?':'.$config['hostport']:'').'/'.$config['database'];
  31.         if(!empty($config['charset'])) {
  32.             $dsn  .= ';charset='.$config['charset'];
  33.         }
  34.         return $dsn;
  35.     }
  36.  
  37.     /**
  38.      * 执行语句
  39.      * @access public
  40.      * @param string $str  sql指令
  41.      * @param boolean $fetchSql  不执行只是获取SQL    
  42.      * @return integer
  43.      */
  44.     public function execute($str,$fetchSql=false) {
  45.         $this->initConnect(true);
  46.         if ( !$this->_linkID ) return false;
  47.         $this->queryStr = $str;
  48.         if(!empty($this->bind)){
  49.             $that   =   $this;
  50.             $this->queryStr =   strtr($this->queryStr,array_map(function($val) use($that){ return '\''.$that->escapeString($val).'\''; },$this->bind));
  51.         }
  52.         if($fetchSql){
  53.             return $this->queryStr;
  54.         }
  55.         $flag = false;
  56.         if(preg_match("/^\s*(INSERT\s+INTO)\s+(\w+)\s+/i", $str, $match)) {
  57.             $this->table = C("DB_SEQUENCE_PREFIX").str_ireplace(C("DB_PREFIX"), "", $match[2]);
  58.             $flag = (boolean)$this->query("SELECT * FROM user_sequences WHERE sequence_name='" . strtoupper($this->table) . "'");
  59.         }
  60.         //释放前次的查询结果
  61.         if ( !empty($this->PDOStatement) ) $this->free();
  62.         $this->executeTimes++;
  63.         N('db_write',1); // 兼容代码        
  64.         // 记录开始执行时间
  65.         $this->debug(true);
  66.         $this->PDOStatement     =       $this->_linkID->prepare($str);
  67.         if(false === $this->PDOStatement) {
  68.             $this->error();
  69.             return false;
  70.         }
  71.         foreach ($this->bind as $key => $val) {
  72.             if(is_array($val)){
  73.                 $this->PDOStatement->bindValue($key, $val[0], $val[1]);
  74.             }else{
  75.                 $this->PDOStatement->bindValue($key, $val);
  76.             }
  77.         }
  78.         $this->bind =   array();        
  79.         $result =       $this->PDOStatement->execute();
  80.         $this->debug(false);
  81.         if ( false === $result) {
  82.             $this->error();
  83.             return false;
  84.         } else {
  85.             $this->numRows = $this->PDOStatement->rowCount();
  86.             if($flag || preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
  87.                 $this->lastInsID = $this->_linkID->lastInsertId();
  88.             }
  89.             return $this->numRows;
  90.         }
  91.     }
  92.  
  93.     /**
  94.      * 取得数据表的字段信息
  95.      * @access public
  96.      */
  97.      public function getFields($tableName) {
  98.         list($tableName) = explode(' ', $tableName);
  99.         $result = $this->query("select a.column_name,data_type,decode(nullable,'Y',0,1) notnull,data_default,decode(a.column_name,b.column_name,1,0) pk "
  100.                   ."from user_tab_columns a,(select column_name from user_constraints c,user_cons_columns col "
  101.           ."where c.constraint_name=col.constraint_name and c.constraint_type='P'and c.table_name='".strtoupper($tableName)
  102.           ."') b where table_name='".strtoupper($tableName)."' and a.column_name=b.column_name(+)");
  103.         $info   =   array();
  104.         if($result) {
  105.             foreach ($result as $key => $val) {
  106.                 $info[strtolower($val['column_name'])] = array(
  107.                     'name'    => strtolower($val['column_name']),
  108.                     'type'    => strtolower($val['data_type']),
  109.                     'notnull' => $val['notnull'],
  110.                     'default' => $val['data_default'],
  111.                     'primary' => $val['pk'],
  112.                     'autoinc' => $val['pk'],
  113.                 );
  114.             }
  115.         }
  116.         return $info;
  117.     }
  118.  
  119.     /**
  120.      * 取得数据库的表信息(暂时实现取得用户表信息)
  121.      * @access public
  122.      */
  123.     public function getTables($dbName='') {
  124.         $result = $this->query("select table_name from user_tables");
  125.         $info   =   array();
  126.         foreach ($result as $key => $val) {
  127.             $info[$key] = current($val);
  128.         }
  129.         return $info;
  130.     }
  131.  
  132.     /**
  133.      * SQL指令安全过滤
  134.      * @access public
  135.      * @param string $str  SQL指令
  136.      * @return string
  137.      */
  138.     public function escapeString($str) {
  139.         return str_ireplace("'", "''", $str);
  140.     }
  141.  
  142.     /**
  143.      * limit
  144.      * @access public
  145.      * @return string
  146.      */
  147.         public function parseLimit($limit) {
  148.         $limitStr    = '';
  149.         if(!empty($limit)) {
  150.             $limit      =       explode(',',$limit);
  151.             if(count($limit)>1)
  152.                 $limitStr = "(numrow>" . $limit[0] . ") AND (numrow<=" . ($limit[0]+$limit[1]) . ")";
  153.             else
  154.                 $limitStr = "(numrow>0 AND numrow<=".$limit[0].")";
  155.         }
  156.         return $limitStr?' WHERE '.$limitStr:'';
  157.     }
  158.  
  159.     /**
  160.      * 设置锁机制
  161.      * @access protected
  162.      * @return string
  163.      */
  164.     protected function parseLock($lock=false) {
  165.         if(!$lock) return '';
  166.         return ' FOR UPDATE NOWAIT ';
  167.     }
  168. }
  169.  
downloadOracle.class.php Source code - Download The latest thinkphp v5.2 work order system Source code
Related Source Codes/Software:
V3.3.6 Workerman high-performance PHP Socket (framework) - High performance PHP Socket framework Workerman re... 2017-05-03
The phosphor meeting room reservation system MRBS (loop reservation v16.0) - The phosphor meeting room reservation system MRBS ... 2017-05-03
IDC v5.2.3 agent center - IDC Centre IDC for exploitation is a PHP+MySQL age... 2017-05-03
Zen master v9.0.1 project management software - Zen is the first domestic open source project mana... 2017-05-03
Ray speed v7.03 employee files management system - Employee files project is various, and some conten... 2017-05-03
HITCMS Haitian responsive electronic mechanical v3.0 foreign trade website source code - HITCMS Haitian response electronic machinery trade... 2017-05-03
Ray v7.02 speed survey system - Lightning speed survey system is a. NET+MSSQL deve... 2017-05-03
Cool HITCMS reactive black v3.0 enterprise website source code - HITCMS-Haitian response black enterprises website ... 2017-05-03
WebOA v17.2 network office automation system - WebOA network using b/s structure development of o... 2017-05-03
Pure imitation of han site source code, one a 】 【 c9cms kernel v1.0 - Generic http://www.wufazhuce.com/Han one · Config... 2017-05-04
zone.js - Implements Zones for JavaScript ... 2017-05-11
dragonfly - A Ruby gem for on-the-fly processing - suitable fo... 2017-05-11
oh-my-fish - The Fishshell Framework. 2017-05-11
canvas-lms - The open LMS by Instructure, Inc. 2017-05-11
ledger - Double-entry accounting system with a command-line... 2017-05-11
Python - My Python Examples http://w... 2017-05-11
blade - 2017-05-11
LaZagne - Credentials recovery project 2017-05-10
Pull-to-Refresh.Rentals-iOS - This project aims to provide a simple and customiz... 2017-05-10
spoon - Distributing instrumentation tests to all your And... 2017-05-10

 Back to top