class_PDOLevel.inc.php
9.26 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
/**
* @file PDOLevel.inc.php
* @category freeSN
* @mailto code [at] netz.coop
* @version 0.4.200901
* @link http://netz.coop
*
* @copyright Copyright by netz.coop e.G. 2015
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
abstract class PDOLevel extends BasicMySql {
protected $PDOObject = null;
public function __construct(array $param_DataBaseData, PDO $param_PDO=null){
parent::__construct($param_DataBaseData, $param_PDO);
$this->PDOObject = $param_PDO;
}
public function PDO_query($param_query, array $param_bindValueArray=null) {
$stmt = $this->PDOObject->prepare($param_query);
if(!$stmt) {
D::backtrace('PDO SQL ERROR');
D::ulli("PDO_query(".$param_query.")");
D::show($this->PDOObject->errorInfo(), $this->PDOObject->errorCode());
D::show(PDO::getAvailableDrivers ( void ), 'PDO::getAvailableDrivers ( void )');
ErrorEvent::handleError($param_typ='PDOSql', $param_query, $param_file='PDOLevel', $param_row='17', $param_More="error(".$this->PDOObject->errorInfo().")");
return false;
}
if($param_bindValueArray!==null) {
foreach($param_bindValueArray as $key => $value) {
$stmt->bindValue($key,$value);
}
}
//D::backtrace();
$stmt->execute();
return $stmt;
}
public function PDO_nextRow($param_stmt) {
return $param_stmt->fetch(PDO::FETCH_ASSOC);
}
public function PDO_getResultRow($param_stmt) {
$var_result = $param_stmt->fetch(PDO::FETCH_ASSOC);
$param_stmt->closeCursor();
return $var_result;
}
public function PDO_fetchAll($param_stmt) {
$var_result = $param_stmt->fetchAll(PDO::FETCH_ASSOC);
$param_stmt->closeCursor();
return $var_result;
}
public function getClassName($param_ClassID) {
if(array_key_exists($param_ClassID, $this->Cache_ClassNameArray)) {
return $this->Cache_ClassNameArray[$param_ClassID];
} else {
$stmt = $this->PDO_query("select ClassName from losp_class where ClassID= :ClassID", array(':ClassID' => $param_ClassID));
$row = $this->PDO_getResultRow($stmt);
$this->Cache_ClassNameArray[$param_ClassID] = $row['ClassName'];
return $row['ClassName'];
}
}
/**
* @todo evt. noch mal schauen ob es dafür eine PDO Funktion gibt
*
* @param <type> $param_ObjectName
* @return <type>
*/
public function getTableDescript($param_ObjectName){
if(class_exists($param_ObjectName)) {
$TableName = CONFIG::getSQL_Data($param_ObjectName, 'Tablename');
if($TableName) {
} else if($param_ObjectName=='MultimediaText') {
$TableName = 'losp_BasisElement';
} else return Error::newError('DevError','');
} else {
$TableName = $param_ObjectName;
}
if(!array_key_exists($TableName, $this->Cache_TableDescription)) {
$this->Cache_TableDescription[$TableName] = array();
$stmt = $this->PDO_query('DESCRIBE '.$TableName.';');
foreach($this->PDO_fetchAll($stmt) as $spalten) {
$Length = substr($spalten["Type"], (stripos($spalten["Type"], '(')+1));
$Length = substr($Length, 0, (stripos($Length, ')')));
$spalten["Length"] = $Length;
$this->Cache_TableDescription[$TableName][$spalten["Field"]] = $spalten;
if(strpos($this->Cache_TableDescription[$TableName][$spalten["Field"]]['Type'] , '(' )) {
$this->Cache_TableDescription[$TableName][$spalten["Field"]]['Type'] = substr($this->Cache_TableDescription[$TableName][$spalten["Field"]]['Type'], 0, strpos($this->Cache_TableDescription[$TableName][$spalten["Field"]]['Type'] , '(' ) );
}
}
// D::show($this->Cache_TableDescription[$TableName], $TableName);
}
return $this->Cache_TableDescription[$TableName];
}
/**
* Funktion getClassNameFromMTextID gibt den Klassennamen der MTextID zurück
* @param int param_MTextID
* @return string Klassenname
*/
public static $count_getClassNameFromMTextID = 0;
public function getClassNameFromMTextID($param_BEID) {
self::$count_getClassNameFromMTextID++;
if(!array_key_exists($param_BEID, $this->Cache_BEID_ClassNameArray)) {
$stmt = $this->PDO_query(' select ClassID from losp_BasisElement where ID= :ID', array(':ID' => $param_BEID));
$row = $this->PDO_getResultRow($stmt);
$this->Cache_BEID_ClassNameArray[$param_BEID] = $this->getClassName($row['ClassID']);
}
return $this->Cache_BEID_ClassNameArray[$param_BEID];
}
/**
* Funktion gibt den Category namen zurück
*
* @param int $param_ID
* @return string CategoryName || false
*/
public function IDToPartObjVar($param_ID) {
$stmt = $this->PDO_query('select PartOfObjVar from losp_BasisClipboard_objvar where PartOfObjVarID= :PartOfObjVarID', array(':PartOfObjVarID' => $param_ID));
$row = $this->PDO_getResultRow($stmt);
return $row["PartOfObjVar"];
}
public function PartObjVarToID($param_Name) {
if($param_Name) {
$stmt = $this->PDO_query('select PartOfObjVarID from losp_BasisClipboard_objvar where PartOfObjVar= :PartOfObjVar ', array(':PartOfObjVar' => trim($param_Name)));
$row = $this->PDO_getResultRow($stmt);
return $row["PartOfObjVarID"];
} else {
return 0;
}
}
public function CategorynameToID($param_Name) {
if($param_Name) {
$stmt = $this->PDO_query('select CategoryID from losp_BasisClipboard_category where CategoryName= :CategoryName ', array(':CategoryName' => trim($param_Name)));
$row = $this->PDO_getResultRow($stmt);
return $row["CategoryID"];
} else {
return 0;
}
}
/**
* Funktion gibt den Category namen zurück
*
* @param int $param_ID
* @return string CategoryName || false
*/
public function IDToCategoryName($param_ID) {
$stmt = $this->PDO_query('select CategoryName from losp_BasisClipboard_category where CategoryID= :CategoryID', array(':CategoryID' => $param_ID));
$row = $this->PDO_getResultRow($stmt);
return $row["CategoryName"];
}
/**
* return an array with all Attach BasisElement IDs as key and as value the BasisClipboard data
* it don't check the rights and so on
*
* @since 0.4 - 21.04.2009
* @author f
*
* @param int param_PartOfID
* @param string param_ObjVar
* @param string CategoryName
*
* @return array
*/
public function getAllBasisElementIDsForBasisClipboard($param_PartOfID, $param_ObjVar, $param_CategoryName, $param_AttachID=null) {
if($param_PartOfID && $param_ObjVar) {
$var_query = 'select * from losp_BasisClipboard as BC
inner join losp_BasisClipboard_objvar as BCo on BC.PartOfObjVarID=BCo.PartOfObjVarID
left join losp_BasisClipboard_category as BCc on BC.CategoryID=BCc.CategoryID
where
PartOfID= :PartOfID
and
PartOfObjVar= :PartOfObjVar
';
$var_BindValues = array( ':PartOfID' => $param_PartOfID, ':PartOfObjVar' => $param_ObjVar, );
if($param_CategoryName) {
$var_query .= ' and CategoryName= :CategoryName ';
$var_BindValues[':CategoryName'] = $param_CategoryName;
}
if($param_AttachID) {
$var_query .= ' and AttachID= :AttachID ';
$var_BindValues[':AttachID'] = $param_AttachID;
}
$stmt = $this->PDO_query($var_query, $var_BindValues);
$result = array();
foreach($this->PDO_fetchAll($stmt) as $row) {
$result[$row['AttachID']] = $row;
}
return $result;
} else {
return false;
}
}
public function Profile_IDToNickName($ProfileID){
if(is_numeric($ProfileID)) {
$stmt = $this->PDO_query('select NickName from '.CONFIG::getSQL_Data('Profile', 'Tablename').' where MTextID= :MTextID', array(':MTextID' => $ProfileID));
$row = $this->PDO_getResultRow($stmt);
return $row["NickName"];
} else {
return $ProfileID;
}
}
public function Profile_NickNameToID($ProfileNickName){
$stmt = $this->PDO_query('select MTextID from '.CONFIG::getSQL_Data('Profile', 'Tablename').' where NickName= :NickName', array(':NickName' => $ProfileNickName));
$row = $this->PDO_getResultRow($stmt);
return $row["MTextID"];
}
public function Profile_IDToAvatar($ProfileID){
$stmt = $this->PDO_query('select Avatar from '.CONFIG::getSQL_Data('Profile', 'Tablename').' where MTextID= :MTextID', array(':MTextID' => $ProfileID));
$row = $this->PDO_getResultRow($stmt);
return $row["Avatar"];
}
public function Profile_IDToSignature($ProfileID){
$stmt = $this->PDO_query('select Signature from '.CONFIG::getSQL_Data('Profile', 'Tablename').' where MTextID= :MTextID', array(':MTextID' => $ProfileID));
$row = $this->PDO_getResultRow($stmt);
return $row["Signature"];
}
public function Account_checkPassword($param_User, $param_Password) {
$stmt = $this->PDO_query('select ID, Password from losp_be_account where ProfileID= :ProfileID ', array(':ProfileID' => Profile::NickNameToID($this,$param_User)));
$row = $this->PDO_getResultRow($stmt);
if ($row["Password"] == $param_Password) {
return $row["ID"];
} else return Error::newError('UserError','WrongLogIn','Username or Password wrong');
}
}
?>