Subversion Repositories Sigmater

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 Andrea 1
<?php
2
 
3
function db_connect ($user, $pwd, $alias) {	
4
 
5
	global $ocierr;
6
 
7
	$dbconn = OCINLogon($user, $pwd, $alias);
8
 
9
	$ocierr = OCIError();
10
 
11
	return $dbconn;
12
 
13
}
14
 
15
function fetch_into_list ($stmt,$assoc) {
16
 
17
	$arr_bid_list = '';
18
 
19
    if ($assoc) {
20
 
21
        while (OCIFetchInto($stmt, $arr, OCI_ASSOC+OCI_RETURN_NULLS)) {
22
                $arr_bid_list[] = $arr;
23
        }
24
    }
25
    else {
26
 
27
        while (OCIFetchInto($stmt, $arr, OCI_RETURN_NULLS)) {
28
                $arr_bid_list[] = $arr;
29
        }
30
    }
31
 
32
    return $arr_bid_list;
33
}
34
 
35
function exec_sql($conn, $sql, $autocommit = 0, $options = '') {
36
 
37
	global $ocierr;
38
 
39
	$ocierr = false;
40
 
41
 
42
	if (is_array($options) && isset($options['INS_BLOB'])) {
43
 
44
		global $GL_OCI_LOB;
45
 
46
		$GL_OCI_LOB = OCINewDescriptor($conn, OCI_D_LOB);
47
 
48
		$sql .= ' returning '.$options['INS_BLOB'].' into :oci_lob';
49
	}
50
    if (!($dbstmt = @OCIParse($conn, $sql))) {
51
 
52
		$msg = ' OCIParse fallita';
53
		$ocierr = array('message' => $msg, 'code' => 'OCIPARSE', 'sqltext' => $sql);
54
                //print_r($ocierr);
55
        if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
56
        	return array(false, $msg.': '.$sql);
57
        else
58
        	return false;
59
    }
60
 
61
	if (isset($GL_OCI_LOB)) {
62
 
63
		OCIBindByName($dbstmt, ':oci_lob', $GL_OCI_LOB, -1, OCI_B_BLOB);
64
	}
65
 
66
    if ($autocommit == 1)
67
		$ret = @OCIExecute($dbstmt, OCI_COMMIT_ON_SUCCESS);
68
    else
69
        $ret = @OCIExecute($dbstmt, OCI_DEFAULT);
70
 
71
    if (!$ret) {
72
 
73
        $ocierr = OCIError($dbstmt);
74
	  //print_r($ocierr);	
75
		if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
76
			return array(false, $ocierr['message']);
77
		else
78
        	return false;
79
    }
80
 
81
	if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
82
    	return array($dbstmt, '');
83
    else	
84
    	return $dbstmt;
85
}
86
 
87
function exec_select($conn, $sql) {
88
 
89
	if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION) {
90
 
91
		list($stmt, $err) = exec_sql($conn, $sql);
92
 
93
		if ($stmt === false) {
94
			return array('', $err);
95
		}
96
 
97
		$nrighe = @OCIFetchStatement($stmt, $result);
98
 
99
		if ($nrighe == 0)
100
			return array('', 'NODATA');
101
		else
102
			return array($result, '');	        
103
 
104
	}
105
	else {
106
 
107
        $stmt = exec_sql($conn, $sql);
108
 
109
        if ($stmt === false)
110
        	return false;
111
 
112
        $nrighe = @OCIFetchStatement($stmt, $result);
113
 
114
        if ($nrighe == 0)
115
			return 'NODATA';
116
        else
117
            return $result;			
118
	}	            
119
}
120
 
121
function oracle_date($formato = '') {
122
 
123
    global $conn;
124
 
125
    $f = ($formato == '') ? 'dd/mm/yyyy hh24:mi:ss' : $formato;
126
 
127
    $sql = "select to_char(sysdate, '$f') A from dual";
128
 
129
    $stmt = exec_sql($conn, $sql, 0);
130
 
131
    if(!$stmt) {
132
 
133
        return false;
134
    }
135
    else {
136
 
137
		OCIFetch($stmt);
138
        $date = OCIResult($stmt, 'A');
139
        @OCIFreeStatement($stmt);
140
        return $date;
141
    }
142
}
143
 
144
function exec_select_format($conn, $sql, $assoc = false) {
145
 
146
	if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION) {
147
 
148
		list($stmt, $err) = exec_sql($conn, $sql);
149
 
150
		if ($stmt === false)
151
			return array('', $err);
152
 
153
		$result = fetch_into_list ($stmt, $assoc);
154
 
155
		if ($result == '')
156
			return array('', 'NODATA');
157
		else
158
			return array($result, '');
159
	}
160
	else {
161
 
162
        $stmt = exec_sql($conn, $sql);
163
 
164
        if ($stmt === false)
165
            return false;
166
 
167
        $result = fetch_into_list ($stmt, $assoc);
168
 
169
        if ($result == '')
170
            return 'NODATA';
171
        else
172
			return $result;
173
	}
174
}
175
 
176
// Funzione By Matteo Merani per Apache 2
177
function exec_sql_blob($conn, $sql, $autocommit = 0, $options,$file_blob) {
178
 
179
  global $ocierr;
180
  $ocierr = false;
181
 
182
  if (is_array($options) && isset($options['INS_BLOB'])) {
183
        $GL_OCI_LOB = OCINewDescriptor($conn, OCI_D_LOB);
184
        $sql .= ' returning '.$options['INS_BLOB'].' into :oci_lob';
185
  }
186
 
187
  if (!($dbstmt = OCIParse($conn, $sql))) {
188
        $msg = ' OCIParse fallita';
189
        $ocierr = array('message' => $msg, 'code' => 'OCIPARSE', 'sqltext' => $sql);
190
        if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
191
              return array(false, $msg.': '.$sql);
192
        else
193
               return false;
194
  }
195
 
196
  if (isset($GL_OCI_LOB)) {
197
        OCIBindByName($dbstmt, ':oci_lob', $GL_OCI_LOB, -1, OCI_B_BLOB);
198
 
199
  }
200
  if ($autocommit == 1)
201
        $ret = @OCIExecute($dbstmt, OCI_COMMIT_ON_SUCCESS);
202
  else
203
        $ret = @OCIExecute($dbstmt, OCI_DEFAULT);
204
 
205
  if (!$ret) {
206
        $ocierr = OCIError($dbstmt);
207
        if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
208
                return array(false, $ocierr['message']);
209
        else
210
               return false;
211
  }
212
  if (isset($GL_OCI_LOB)) {
213
        if (!$GL_OCI_LOB->save($file_blob)) {
214
        $msg = ' Salvataggio Blob fallito';
215
        $ocierr = array('message' => $msg, 'code' => 'SAVEBLOB', 'sqltext' => $sql);
216
        return false;
217
        }
218
  }
219
 
220
  if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
221
        return array($dbstmt, '');
222
   else
223
        return $dbstmt;
224
  }
225
 
226
// Funzione By Matteo Merani per Apache 2
227
function exec_sql_blob_file($conn, $sql, $autocommit = 0, $options,$file_blob) {
228
 
229
  global $ocierr;
230
  $ocierr = false;
231
 
232
  if (is_array($options) && isset($options['INS_BLOB'])) {
233
        $GL_OCI_LOB = OCINewDescriptor($conn, OCI_D_LOB);
234
        $sql .= ' returning '.$options['INS_BLOB'].' into :oci_lob';
235
  }
236
 
237
  if (!($dbstmt = OCIParse($conn, $sql))) {
238
        $msg = ' OCIParse fallita';
239
        $ocierr = array('message' => $msg, 'code' => 'OCIPARSE', 'sqltext' => $sql);
240
        if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
241
              return array(false, $msg.': '.$sql);
242
        else
243
               return false;
244
  }
245
 
246
  if (isset($GL_OCI_LOB)) {
247
        OCIBindByName($dbstmt, ':oci_lob', $GL_OCI_LOB, -1, OCI_B_BLOB);
248
 
249
  }
250
  if ($autocommit == 1)
251
        $ret = @OCIExecute($dbstmt, OCI_COMMIT_ON_SUCCESS);
252
  else
253
        $ret = @OCIExecute($dbstmt, OCI_DEFAULT);
254
 
255
  if (!$ret) {
256
        $ocierr = OCIError($dbstmt);
257
        print_r($ocierr);
258
        if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
259
                return array(false, $ocierr['message']);
260
        else
261
               return false;
262
  }
263
  if (isset($GL_OCI_LOB)) {
264
        if (!$GL_OCI_LOB->savefile($file_blob)) {
265
        $msg = ' Salvataggio Blob fallito';
266
        $ocierr = array('message' => $msg, 'code' => 'SAVEBLOB', 'sqltext' => $sql);
267
        print_r($ocierr);
268
        return false;
269
        }
270
  }
271
 
272
  if (defined('OCI_DB_OLD_VERSION') && OCI_DB_OLD_VERSION)
273
        return array($dbstmt, '');
274
   else
275
        return $dbstmt;
276
  }
277
?>