This repository was archived by the owner on Feb 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoracle.class.php
More file actions
193 lines (193 loc) · 5.77 KB
/
Copy pathoracle.class.php
File metadata and controls
193 lines (193 loc) · 5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* Class used for handle Oracle 9i(or higher) Connections
* @package PHP2HTML
* @subpackage databases
* @version 1.0 BETA
* @author MANUEL GONZALEZ RIVERA <phptohtml@gmail.com>
* @copyright Copyright (R) 2012, MANUEL GONZALEZ RIVERA <phptohtml@gmail.com>
* @license http://opensource.org/licenses/MIT MIT
*
*/
/**
* SQLFunctions class is needed
* @see SQLFunctions
*/
require_once 'sqlfunctions.class.php';
/**
* Class used for handle Oracle 9i(or higher) Connections
*
* @package PHP2HTML
* @subpackage databases
* @version 1.0
* @author MANUEL GONZALEZ RIVERA <phptohtml@gmail.com>
* @copyright Copyright (R) 2012, MANUEL GONZALEZ RIVERA <phptohtml@gmail.com>
* @license http://opensource.org/licenses/MIT MIT
*
*/
class oracleConn extends SQLFunctions{
/**
* Open the connection
*
*/
protected function Conn() {
try{
if($this->persistant==true){
$this->conn = oci_pconnect($this->user, $this->password, $this->host.'/'.$this->database);
}else{
$this->conn = oci_connect($this->user, $this->password, $this->host.'/'.$this->database);
}
if(!$this->conn){
$e = oci_error();
$this->HtmlC->display_error('oracleConn::Conn()', htmlentities($e['message']));
}
}catch(Exception $e){
$this->HtmlC->display_error('oracleConn::Conn()',$e->getMessage());
}
}
/**
* Close the connection
*/
public function Close() {
$type = (is_resource($this->conn) ? get_resource_type($this->conn) : "none");
if(strstr($type,"oci8")){
oci_close($this->conn);
}else{
if($type!='Unknown'){
$this->HtmlC->display_error('oracleConn::Close()','The active connection is not an Oracle connection. Resource Type: '.$type);
}else{
$this->HtmlC->display_error('oracleConn::Close()','The active connection is an unknow resource type: '.$type);
}
}
}
/**
* Get the connection info
*
* return string
*/
public function ConnSummary() {
return $this->user.'@'.$this->database.':'.$this->host;
}
/**
* Returns an associative array with the following record
*
* @param boolean $assoc
* @return mixed
*/
public function Fetch($assoc = true){
try{
if($assoc==true){
$this->row = oci_fetch_assoc($this->rs);
}else{
$this->row = oci_fetch_array($this->rs);
}
return is_array($this->row);
}catch(Exception $error){
$e = oci_error();
$this->HtmlC->display_error('oracleConn::Fetch()', htmlentities($e['message']));
}
}
/**
* Try running a SQL query. If the parameter is empty, it takes the variable $this->sql
*
* @param string $sql Sql Query
*/
public function Query($sql = ''){
try{
if(is_resource($this->rs)) {
oci_free_statement($this->rs);
}
$this->sql = ($sql == "" ? $this->sql : $sql);
$this->rs = oci_parse($this->conn, $this->sql);
}catch(Exception $error){
$e = oci_error();
$this->HtmlC->display_error('oracleConn::Query()', htmlentities($e['message']));
}
}
/**
* Move the pointer to the index consultation indicated
* Does not works in Oracle
*
* @todo find alternatives
* @param int $num
* @return boolean false
*/
public function Seek($num = 0) {
$this->HtmlC->display_error('oracleConn::Seek()', 'The seek function is not available at Oracle connections');
return false;
}
/**
* Initialize the class
*
* @param $host string
* @param $database string
* @param $user string
* @param $password string
* @param $persistant boolean
*/
public function __construct($obj, $host =DB_HOST, $database = DB_DATABASE, $user = DB_USER, $password = DB_PASS, $persistant = DB_PERSIST) {
$this->HtmlC = $obj;
$this->host = $host;
$this->database = $database;
$this->user = $user;
$this->password = $password;
$this->persistant = $persistant;
$this->Conn();
}
/**
* Destroy
*/
public function __destruct() {
try{
$this->Close();
}catch(Exception $e){
echo "Error: ". $e->getMessage();
}
}
/**
* Returns the number of rows affected by a query update, insert or delete
*
* @return int
*/
public function affectedRows() {
if(!empty($this->rs)){
return oci_num_rows($this->conn);
}else{
return 0;
}
}
/**
* Return the last id inserted
* Does not works in Oracle
*
* @todo Find alternatives
* @return int 0
*/
public function getInsertedId() {
$this->HtmlC->display_error('oracleConn::getInsertedId()', 'The getInsertedId function is not available at Oracle connections');
return 0;
}
/**
* Returns the number of columns in the query result
*
* @return int
*/
public function numColumns() {
if(!empty($this->rs)){
return oci_num_fields($this->conn);
}else{
return 0;
}
}
/**
* Returns the number of rows for a SELECT query resolved
* Does not work in oracle
* @todo Find alternatives
* @return int
*/
public function numRows() {
$this->HtmlC->display_error('oracleConn::numRows()', 'The numRows function is not available at Oracle connections');
return 0;
}
}
?>