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