MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mconnection.class
Ir para a documentação deste ficheiro.
1<?php
2
4{
5 var $db; // database object
6 var $id; // the connection identifier
7 var $traceback = array(); // a list of connection errors
9
14 var $_miolo; // MIOLO object
15
16 function __construct($db)
17 {
18 $this->db = $db;
19 $this->_miolo = $this->db->_miolo;
20 $this->_miolo->Uses('database/' . $db->system . '/mquery.class');
21 }
22
23 // Virtual methods - to be implemented by the specific drivers
24
25 public function _connect($dbhost, $LoginDB, $LoginUID, $LoginPWD, $persistent = true, $port='')
26 {
27 }
28
29 public function _close()
30 {
31 }
32
33 public function _error()
34 {
35 }
36
37 public function _execute($sql)
38 {
39 }
40
41 public function _createquery()
42 {
43 }
44
45 public function _createproc()
46 {
47 }
48
49 public function _chartotimestamp($timestamp)
50 {
51 }
52
53 public function _chartodate($date)
54 {
55 }
56
57 public function _timestamptochar($timestamp)
58 {
59 }
60
61 public function _datetochar($date)
62 {
63 }
64
65 // opens a connection to the specified data source
66 function Open($dbhost, $LoginDB, $LoginUID, $LoginPWD, $persistent = true, $parameters = NULL, $port=NULL)
67 {
68 if ($this->id)
69 {
70 $this->Close();
71 }
72 $this->_connect($dbhost, $LoginDB, $LoginUID, $LoginPWD, $persistent, $parameters, $port);
73 if (!$this->id)
74 {
75 $this->traceback[] = "Unable to estabilish DataBase Conection to host: $dbhost, DB: $LoginDB";
76 }
77 return $this->id;
78 }
79
80 function Close()
81 {
82 if ($this->id)
83 {
84 $this->_close($this->id);
85 $this->id = 0;
86 }
87 }
88
89 function GetError()
90 {
91 if (!$this->id)
92 {
93 $err = _M("No valid Database connection estabilished.");
94 }
95 elseif ($this->traceback)
96 {
97 $err .= "<br>" . implode("<br>", $this->traceback);
98 }
99 return $err;
100 }
101
102 function GetErrors()
103 {
104 return $this->traceback;
105 }
106
107 function GetErrorCount()
108 {
109 return count($this->traceback);
110 }
111
112 function CheckError()
113 {
114 if (empty($this->traceback))
115 {
116 return;
117 }
118 $n = count($this->traceback);
119 if ($n > 0)
120 {
121 $msg = "";
122 for ($i = 0; $i < $n; $i++)
123 {
124 $msg .= $this->traceback[$i] . "<br>";
125 }
126 }
127 if ($msg != '')
128 {
129 throw new EDatabaseException($this->db->conf, $msg);
130 }
131 }
132
133 function Execute($sql)
134 {
135 $this->_miolo->LogSQL($sql, false, $this->db->conf);
136
137 if (!($success = $this->_execute($sql)))
138 {
139 throw new EDatabaseExecException($this->GetError());
140 }
141
142 return $success;
143 }
144
145 function Parse($sql)
146 {
147 $this->_miolo->LogSQL( _M('Parse: ') . $sql->command, false, $this->db->conf);
148 $sql->stmt = $this->_parse($sql->command);
149 }
150
151 function Bind($sql)
152 {
153 if ($binds = $sql->parameters)
154 {
155 foreach ($binds as $ph => $pv)
156 {
157 $this->_bind($sql->stmt, $ph, $pv);
158 }
159 }
160 }
161
162 function getQuery($sql, $maxrows = null, $offset = null)
163 {
164 $this->_miolo->Assert($this->id, $this->GetErrors());
165 try
166 {
167 $query = $this->_createquery();
168 $query->SetConnection($this);
169 $query->SetSQL($sql);
170 if ($sql->bind)
171 {
172 if (!$sql->stmt)
173 {
174 $this->Parse($sql);
175 }
176
177 $this->Bind($sql);
178 }
179
180 $query->Open($maxrows, $offset, $sql->stmt);
181 }
182 catch( Exception $e )
183 {
184 throw $e;
185 }
186
187 return $query;
188 }
189
190 function getQueryCommand($sqlCommand, $maxrows = null, $offset = null)
191 {
192 $this->_miolo->Assert($this->id, $this->GetErrors());
193 $query = $this->_createquery();
194 $query->SetConnection($this);
195 $query->SetSQLCommand($sqlCommand);
196 $query->Open($maxrows, $offset);
197 return $query;
198 }
199
200 function ExecProc($sql, $aParams = null)
201 {
202 $this->_miolo->Assert($this->id, $this->GetErrors());
203 $q = $this->_createproc();
204 $q->conn = &$this;
205 if ($sql != "")
206 {
207 $q->ExecProc($sql, $aParams);
208 }
209 return ($q->result ? $q->result : (!$q->error));
210 }
211}
212?>
_timestamptochar($timestamp)
_datetochar($date)
Open($dbhost, $LoginDB, $LoginUID, $LoginPWD, $persistent=true, $parameters=NULL, $port=NULL)
ExecProc($sql, $aParams=null)
getQuery($sql, $maxrows=null, $offset=null)
getQueryCommand($sqlCommand, $maxrows=null, $offset=null)
_connect($dbhost, $LoginDB, $LoginUID, $LoginPWD, $persistent=true, $port='')
_chartodate($date)
_chartotimestamp($timestamp)