1
1
<?php
2
- /*=================================================================================*\
3
- |* This file is part of InMaFSS *|
4
- |* InMaFSS - INformation MAnagement for School Systems - Keep yourself up to date! *|
5
- |* ############################################################################### *|
6
- |* Copyright (C) flx5 *|
7
-
8
- |* ############################################################################### *|
9
- |* InMaFSS is free software; you can redistribute it and/or modify *|
10
- |* it under the terms of the GNU Affero General Public License as published by *|
11
- |* the Free Software Foundation; either version 3 of the License, *|
12
- |* or (at your option) any later version. *|
13
- |* ############################################################################### *|
14
- |* InMaFSS is distributed in the hope that it will be useful, *|
15
- |* but WITHOUT ANY WARRANTY; without even the implied warranty of *|
16
- |* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *|
17
- |* See the GNU Affero General Public License for more details. *|
18
- |* ############################################################################### *|
19
- |* You should have received a copy of the GNU Affero General Public License *|
20
- |* along with InMaFSS; if not, see http://www.gnu.org/licenses/. *|
21
- \*=================================================================================*/
2
+
3
+ /* =================================================================================*\
4
+ |* This file is part of InMaFSS *|
5
+ |* InMaFSS - INformation MAnagement for School Systems - Keep yourself up to date! *|
6
+ |* ############################################################################### *|
7
+ |* Copyright (C) flx5 *|
8
+
9
+ |* ############################################################################### *|
10
+ |* InMaFSS is free software; you can redistribute it and/or modify *|
11
+ |* it under the terms of the GNU Affero General Public License as published by *|
12
+ |* the Free Software Foundation; either version 3 of the License, *|
13
+ |* or (at your option) any later version. *|
14
+ |* ############################################################################### *|
15
+ |* InMaFSS is distributed in the hope that it will be useful, *|
16
+ |* but WITHOUT ANY WARRANTY; without even the implied warranty of *|
17
+ |* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *|
18
+ |* See the GNU Affero General Public License for more details. *|
19
+ |* ############################################################################### *|
20
+ |* You should have received a copy of the GNU Affero General Public License *|
21
+ |* along with InMaFSS; if not, see http://www.gnu.org/licenses/. *|
22
+ \*================================================================================= */
22
23
23
24
class _MySQLI extends SQL {
24
25
@@ -37,6 +38,39 @@ public function __construct($host, $user, $pass, $db) {
37
38
$ this ->username = $ user ;
38
39
$ this ->password = $ pass ;
39
40
$ this ->database = $ db ;
41
+
42
+ $ this ->setConstants ();
43
+ }
44
+
45
+ private function setConstants () {
46
+ define ('DB_TYPE_DECIMAL ' , MYSQLI_TYPE_DECIMAL );
47
+ define ('DB_TYPE_NEWDECIMAL ' , MYSQLI_TYPE_NEWDECIMAL );
48
+ define ('DB_TYPE_BIT ' , MYSQLI_TYPE_BIT );
49
+ define ('DB_TYPE_TINY ' , MYSQLI_TYPE_TINY );
50
+ define ('DB_TYPE_SHORT ' , MYSQLI_TYPE_SHORT );
51
+ define ('DB_TYPE_LONG ' , MYSQLI_TYPE_LONG );
52
+ define ('DB_TYPE_FLOAT ' , MYSQLI_TYPE_FLOAT );
53
+ define ('DB_TYPE_DOUBLE ' , MYSQLI_TYPE_DOUBLE );
54
+ define ('DB_TYPE_NULL ' , MYSQLI_TYPE_NULL );
55
+ define ('DB_TYPE_TIMESTAMP ' , MYSQLI_TYPE_TIMESTAMP );
56
+ define ('DB_TYPE_LONGLONG ' , MYSQLI_TYPE_LONGLONG );
57
+ define ('DB_TYPE_INT24 ' , MYSQLI_TYPE_INT24 );
58
+ define ('DB_TYPE_DATE ' , MYSQLI_TYPE_DATE );
59
+ define ('DB_TYPE_TIME ' , MYSQLI_TYPE_TIME );
60
+ define ('DB_TYPE_DATETIME ' , MYSQLI_TYPE_DATETIME );
61
+ define ('DB_TYPE_YEAR ' , MYSQLI_TYPE_YEAR );
62
+ define ('DB_TYPE_NEWDATE ' , MYSQLI_TYPE_NEWDATE );
63
+ define ('DB_TYPE_INTERVAL ' , MYSQLI_TYPE_INTERVAL );
64
+ define ('DB_TYPE_ENUM ' , MYSQLI_TYPE_ENUM );
65
+ define ('DB_TYPE_SET ' , MYSQLI_TYPE_SET );
66
+ define ('DB_TYPE_TINY_BLOB ' , MYSQLI_TYPE_TINY_BLOB );
67
+ define ('DB_TYPE_MEDIUM_BLOB ' , MYSQLI_TYPE_MEDIUM_BLOB );
68
+ define ('DB_TYPE_LONG_BLOB ' , MYSQLI_TYPE_LONG_BLOB );
69
+ define ('DB_TYPE_BLOB ' , MYSQLI_TYPE_BLOB );
70
+ define ('DB_TYPE_VAR_STRING ' , MYSQLI_TYPE_VAR_STRING );
71
+ define ('DB_TYPE_STRING ' , MYSQLI_TYPE_STRING );
72
+ define ('DB_TYPE_CHAR ' , MYSQLI_TYPE_CHAR );
73
+ define ('DB_TYPE_GEOMETRY ' , MYSQLI_TYPE_GEOMETRY );
40
74
}
41
75
42
76
public function IsConnected () {
@@ -83,17 +117,16 @@ public function DoQuery($query) {
83
117
84
118
return new _MYSQLI_Result ($ resultset );
85
119
}
86
-
120
+
87
121
public function insertID () {
88
122
return $ this ->link ->insert_id ;
89
123
}
90
-
124
+
91
125
public function affected_rows () {
92
126
return $ this ->link ->affected_rows ;
93
127
}
94
-
95
- public function real_escape_string ($ strInput = '' )
96
- {
128
+
129
+ public function real_escape_string ($ strInput = '' ) {
97
130
return $ this ->link ->real_escape_string ($ strInput );
98
131
}
99
132
@@ -109,14 +142,37 @@ public function GetRequests() {
109
142
return $ this ->requests ;
110
143
}
111
144
145
+ public function getErrorList () {
146
+ return $ this ->link ->error_list ;
147
+ }
148
+
149
+ public function getFieldsInfo ($ table ) {
150
+ $ sql = dbquery ("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMN_TYPE FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`=' " . config ("dbname " ) . "' AND `TABLE_NAME`=' " . $ table . "'; " );
151
+
152
+ $ info = Array ();
153
+ while ($ field = $ sql ->fetchObject ()) {
154
+ $ info [$ field ->COLUMN_NAME ] = Array (
155
+ 'name ' => $ field ->COLUMN_NAME ,
156
+ 'type ' => $ field ->DATA_TYPE ,
157
+ 'max_length ' => $ field ->CHARACTER_MAXIMUM_LENGTH ,
158
+ );
159
+
160
+ if ($ field ->DATA_TYPE == 'enum ' ) {
161
+ $ info [$ field ->COLUMN_NAME ]['enum ' ] = explode (", " , str_replace ("' " , "" , substr ($ field ->COLUMN_TYPE , 5 , (strlen ($ field ->COLUMN_TYPE )-6 ))));
162
+ }
163
+ }
164
+
165
+ return $ info ;
166
+ }
167
+
112
168
}
113
169
114
170
class _MYSQLI_Result {
115
171
116
172
private $ res ;
117
173
private $ closed ;
118
174
119
- public function __construct ($ result ) {
175
+ public function __construct ($ result ) {
120
176
$ this ->res = $ result ;
121
177
$ this ->closed = true ; // Use this only if the query uses MYSQLI_USE_RESULT
122
178
}
@@ -129,7 +185,7 @@ public function fetchAssoc() {
129
185
$ ret = $ this ->res ->fetch_assoc ();
130
186
return $ ret ;
131
187
}
132
-
188
+
133
189
public function fetchArray () {
134
190
$ ret = $ this ->res ->fetch_array ();
135
191
return $ ret ;
@@ -138,7 +194,7 @@ public function fetchArray() {
138
194
public function fetchObject () {
139
195
return $ this ->res ->fetch_object ();
140
196
}
141
-
197
+
142
198
public function fetchRow () {
143
199
return $ this ->res ->fetch_row ();
144
200
}
@@ -147,7 +203,21 @@ function result($row = 0, $field = 0) {
147
203
$ this ->res ->data_seek ($ row );
148
204
$ datarow = $ this ->res ->fetch_array ();
149
205
return $ datarow [$ field ];
150
- }
206
+ }
207
+
208
+ function fetchFieldByName ($ columnName ) {
209
+ $ fields = $ this ->fetchFields ();
210
+ foreach ($ fields as $ field ) {
211
+ if ($ field ->name == $ columnName )
212
+ return $ field ;
213
+ }
214
+
215
+ return null ;
216
+ }
217
+
218
+ function fetchFields () {
219
+ return $ this ->res ->fetch_fields ();
220
+ }
151
221
152
222
public function close () {
153
223
if ($ this ->closed )
@@ -161,6 +231,11 @@ public function __destruct() {
161
231
$ this ->close ();
162
232
}
163
233
234
+ // Easy access to parent function
235
+ public function getErrorList () {
236
+ return getVar ("sql " )->getErrorList ();
237
+ }
238
+
164
239
}
165
240
166
241
?>
0 commit comments