MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
connection.class
Ir para a documentação deste ficheiro.
1
<?php
2
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3
# @title
4
# MsSQL Connection
5
#
6
# @description
7
# This file contains MsSQL connection functions
8
#
9
# @see miolo/database.class,
10
# miolo/mssql_query.class,
11
#
12
# @topics db, business
13
#
14
# @created
15
# 2003/09/17
16
#
17
# @organisation
18
# MIOLO - Miolo Development Team - UNIVATES Centro Universitario
19
# http:
//miolo.codigolivre.org.br
20
#
21
# @legal
22
# CopyLeft (L) 2001-2002 UNIVATES, Lajeado/RS - Brasil
23
# Licensed under GPL (see COPYING.TXT or FSF at www.fsf.org for
24
# further details)
25
#
26
# @contributors
27
# Vilson Cristiano Gartner [author] [vgartner@univates.br]
28
# Thomas Spriestersbach [author] [ts@interact2000.com.br]
29
# Clausius Duque G. Reis [user] [clausius@ufv.br]
30
#
31
# @maintainers
32
# Vilson Cristiano Gartner [author] [vgartner@univates.br]
33
# Thomas Spriestersbach [author] [ts@interact2000.com.br]
34
#
35
# history: see miolo cvs.
36
#
37
# @id $Id: mssql_connection.class,v 1.0 2003/09/12 11:18:00 clausius Exp $
38
#---------------------------------------------------------------------
39
47
class
MssqlConnection
48
{
52
var
$conf
;
// name of database configuration
53
57
var
$id
;
// the connection identifier
58
62
var
$traceback
;
// a list of transaction errors
63
67
var
$level
;
// a counter for the transaction level
68
69
79
function
MssqlConnection
(
$conf
)
80
{ global
$MIOLO
;
81
82
$this->conf =
$conf
;
83
84
$MIOLO
->Uses(
'database/mssql_query.class'
);
85
}
86
87
// opens a connection to the specified data source
101
function
Open
($dbhost,$LoginDB,$LoginUID,$LoginPWD,$persistent=
true
)
102
{ global
$MIOLO
, $php_errormsg;
103
104
if
( $this->
id
)
105
{
106
Close
();
107
}
108
109
$this->traceback =
null
;
110
$this->level = 0;
111
112
if
(
false
&& $persistent )
113
{
114
$this->
id
= mssql_pConnect($dbhost,$LoginUID,$LoginPWD);
115
}
116
else
117
{
118
$this->
id
= mssql_Connect($dbhost,$LoginUID,$LoginPWD);
119
}
120
121
if
( ! $this->
id
)
122
{
123
$this->traceback[] =
"Unable to estabilish DataBase Conection to host: $dbhost, DB: $LoginDB"
;
124
}
125
126
return
$this->id
;
127
}
128
129
// closes a previously opened connection
137
function
Close
()
138
{
139
if
( $this->
id
)
140
{ global
$MIOLO
;
141
142
$MIOLO
->Assert($this->level==0,
"Transactions not finished!"
);
143
144
mssql_close($this->
id
);
145
146
$this->
id
= 0;
147
}
148
}
149
157
function
Begin
()
158
{
159
$this->
Execute
(
"begin transaction"
);
160
161
$this->level++;
162
}
163
171
function
Finish
()
172
{ global
$MIOLO
;
173
174
$MIOLO
->Assert($this->level>0,
"Transaction level underrun!"
);
175
176
$success = $this->
GetErrorCount
() == 0;
177
178
if
( $success )
179
{
180
$this->
Execute
(
"commit"
);
181
}
182
else
183
{
184
$this->
Execute
(
"rollback"
);
185
}
186
187
$this->level--;
188
189
return
$success;
190
}
191
199
function
GetError
()
200
{
201
202
if
( ! $this->
id
)
203
{
204
$err =
"No valid Database connection estabilished."
;
205
if
( $this->traceback )
206
{
207
$err .=
"<br>"
. implode(
"<br>"
, $this->traceback);
208
}
209
210
}
211
else
212
{
213
$err = mssql_get_last_message($this->
id
);
214
}
215
return
$err;
216
}
217
218
226
function
GetErrors
()
227
{
228
return
$this->traceback
;
229
}
230
238
function
GetErrorCount
()
239
{
240
return
empty($this->traceback) ? 0 : count($this->traceback);
241
}
242
250
function
CheckError
()
251
{ global
$MIOLO
;
252
253
if
( empty($this->traceback) )
254
{
255
return
;
256
}
257
258
$n = count($this->traceback);
259
260
if
( $n > 0 )
261
{
262
$msg =
""
;
263
264
for
( $i=0; $i<$n; $i++ )
265
{
266
$msg .= $this->traceback[$i] .
"<br>"
;
267
}
268
269
$MIOLO
->Assert(
false
,
"Transaction Error"
,$msg);
270
}
271
}
272
282
function
Execute
($sql)
283
{ global
$MIOLO
;
284
285
$MIOLO
->LogSQL($sql,
false
,$this->conf);
286
287
if
( $this->level == 0 )
288
{
289
$this->traceback =
null
;
290
}
291
292
$rs = mssql_query($this->
id
,$sql);
293
294
$success =
false
;
295
296
if
( $rs )
297
{
298
$success =
true
;
299
300
mssql_free_result($rs);
301
}
302
else
303
{
304
$this->traceback[] = $this->
GetError
();
305
}
306
307
return
$success;
308
}
309
319
function
CreateQuery
($sql=
""
)
320
{ global
$MIOLO
;
321
322
$MIOLO
->Assert($this->
id
, $this->
GetErrors
());
323
324
$q =
new
MssqlQuery
($this->conf);
325
326
$q->conn = $this;
327
$q->sql = $sql;
328
$q->result = 0;
329
$q->row = -1;
330
331
if
( $sql !=
""
)
332
{
333
$q->Open();
334
}
335
336
return
$q;
337
}
338
};
339
340
?>
MssqlConnection
Definição
connection.class:48
MssqlConnection\MssqlConnection
MssqlConnection($conf)
Definição
connection.class:79
MssqlConnection\Close
Close()
Definição
connection.class:137
MssqlConnection\Execute
Execute($sql)
Definição
connection.class:282
MssqlConnection\$traceback
$traceback
Definição
connection.class:62
MssqlConnection\GetErrors
GetErrors()
Definição
connection.class:226
MssqlConnection\Begin
Begin()
Definição
connection.class:157
MssqlConnection\CheckError
CheckError()
Definição
connection.class:250
MssqlConnection\$level
$level
Definição
connection.class:67
MssqlConnection\Finish
Finish()
Definição
connection.class:171
MssqlConnection\GetErrorCount
GetErrorCount()
Definição
connection.class:238
MssqlConnection\Open
Open($dbhost, $LoginDB, $LoginUID, $LoginPWD, $persistent=true)
Definição
connection.class:101
MssqlConnection\CreateQuery
CreateQuery($sql="")
Definição
connection.class:319
MssqlConnection\$conf
$conf
Definição
connection.class:52
MssqlConnection\GetError
GetError()
Definição
connection.class:199
MssqlConnection\$id
$id
Definição
connection.class:57
MssqlQuery
Definição
query.class:53
$MIOLO
$MIOLO
Definição
mdatetimefield.class:25
classes
database
mssql
connection.class
Gerado por
1.10.0