Completed
Push — master ( e05b94...851b65 )
by Daniel
23:53
created

MySQLiByDanielGP   D

Complexity

Total Complexity 112

Size/Duplication

Total Lines 553
Duplicated Lines 7.78 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 21
Bugs 0 Features 2
Metric Value
wmc 112
c 21
b 0
f 2
lcom 2
cbo 4
dl 43
loc 553
rs 4.8717

22 Methods

Rating   Name   Duplication   Size   Complexity  
A connectToMySql() 0 15 3
A getMySQLactiveDatabases() 0 4 1
A getMySQLactiveEngines() 0 4 1
A getMySQLgenericInformations() 0 12 2
A getMySQLglobalVariables() 0 4 1
A getMySQLlistColumns() 0 4 1
A getMySQLlistDatabases() 0 4 1
A getMySQLlistEngines() 0 4 1
A getMySQLlistIndexes() 0 4 1
C getMySQLlistMultiple() 0 37 11
A getMySQLStatistics() 0 4 1
A getMySQLlistTables() 0 4 1
A getMySQLqueryWithParameterIdentifier() 0 8 2
A getMySQLserverTime() 0 4 1
A getRowDataFromTable() 0 12 3
C setArrayToFilterValues() 0 40 14
A setFieldNumbers() 0 12 4
B setFieldSpecific() 0 18 7
A setFldLmts() 0 8 2
A setFldLmtsExact() 0 15 2
C setMySQLquery2Server() 19 70 19
D setMySQLquery2ServerByPattern() 24 120 33

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like MySQLiByDanielGP often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use MySQLiByDanielGP, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2015 Daniel Popiniuc
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
 * SOFTWARE.
26
 *
27
 */
28
29
namespace danielgp\common_lib;
30
31
/**
32
 * Usefull functions to get quick MySQL content
33
 *
34
 * @author Daniel Popiniuc
35
 */
36
trait MySQLiByDanielGP
37
{
38
39
    use DomComponentsByDanielGP,
40
        MySQLiMultiple,
41
        MySQLiByDanielGPqueries,
42
        MySQLiByDanielGPtypes;
43
44
    /**
45
     * Intiates connection to MySQL
46
     *
47
     * @param array $mySQLconfig
48
     *
49
     * $mySQLconfig           = [
50
     * 'host'     => MYSQL_HOST,
51
     * 'port'     => MYSQL_PORT,
52
     * 'username' => MYSQL_USERNAME,
53
     * 'password' => MYSQL_PASSWORD,
54
     * 'database' => MYSQL_DATABASE,
55
     * ];
56
     */
57
    protected function connectToMySql($mySQLconfig)
58
    {
59
        if (is_null($this->mySQLconnection)) {
60
            extract($mySQLconfig);
61
            $this->mySQLconnection = new \mysqli($host, $username, $password, $database, $port);
62
            if (is_null($this->mySQLconnection->connect_error)) {
63
                return '';
64
            }
65
            $erNo                  = $this->mySQLconnection->connect_errno;
66
            $erMsg                 = $this->mySQLconnection->connect_error;
67
            $this->mySQLconnection = null;
68
            $msg                   = $this->lclMsgCmn('i18n_Feedback_ConnectionError');
69
            return sprintf($msg, $erNo, $erMsg, $host, $port, $username, $database);
70
        }
71
    }
72
73
    /**
74
     * returns a list of MySQL databases
75
     *
76
     * @return array
77
     */
78
    protected function getMySQLactiveDatabases()
79
    {
80
        return $this->getMySQLlistDatabases(true);
81
    }
82
83
    /**
84
     * returns a list of active MySQL engines
85
     *
86
     * @return array
87
     */
88
    protected function getMySQLactiveEngines()
89
    {
90
        return $this->getMySQLlistEngines(true);
91
    }
92
93
    /**
94
     * returns the list of all MySQL generic informations
95
     *
96
     * @return array
97
     */
98
    protected function getMySQLgenericInformations()
99
    {
100
        if (is_null($this->mySQLconnection)) {
101
            $line = [];
102
        } else {
103
            $line = [
104
                'Info'    => $this->mySQLconnection->server_info,
105
                'Version' => $this->mySQLconnection->server_version
106
            ];
107
        }
108
        return $line;
109
    }
110
111
    /**
112
     * returns the list of all MySQL global variables
113
     *
114
     * @return array
115
     */
116
    protected function getMySQLglobalVariables()
117
    {
118
        return $this->getMySQLlistMultiple('VariablesGlobal', 'array_key_value');
119
    }
120
121
    /**
122
     * returns a list of MySQL indexes (w. choice of to choose any combination of db/table/column)
123
     *
124
     * @return array
125
     */
126
    protected function getMySQLlistColumns($filterArray = null)
127
    {
128
        return $this->getMySQLlistMultiple('Columns', 'full_array_key_numbered', $filterArray);
129
    }
130
131
    /**
132
     * returns a list of MySQL databases (w. choice of exclude/include the system ones)
133
     *
134
     * @return array
135
     */
136
    protected function getMySQLlistDatabases($excludeSystemDbs = true)
137
    {
138
        return $this->getMySQLlistMultiple('Databases', 'array_first_key_rest_values', $excludeSystemDbs);
139
    }
140
141
    /**
142
     * returns a list of MySQL engines (w. choice of return only the active ones)
143
     *
144
     * @return array
145
     */
146
    protected function getMySQLlistEngines($onlyActiveOnes = true)
147
    {
148
        return $this->getMySQLlistMultiple('Engines', 'array_first_key_rest_values', $onlyActiveOnes);
149
    }
150
151
    /**
152
     * returns a list of MySQL indexes (w. choice of to choose any combination of db/table/column)
153
     *
154
     * @return array
155
     */
156
    protected function getMySQLlistIndexes($filterArray = null)
157
    {
158
        return $this->getMySQLlistMultiple('Indexes', 'full_array_key_numbered', $filterArray);
159
    }
160
161
    /**
162
     * Return various informations (from predefined list) from the MySQL server
163
     *
164
     * @return string
165
     */
166
    private function getMySQLlistMultiple($returnChoice, $returnType, $additionalFeatures = null)
167
    {
168
        if (is_null($this->mySQLconnection)) {
169
            if ($returnType == 'value') {
170
                return null;
171
            }
172
            return [];
173
        }
174
        $query = '';
175
        switch ($returnChoice) {
176
            case 'Columns':
177
                $query = $this->sQueryMySqlColumns($additionalFeatures);
178
                break;
179
            case 'Databases':
180
                $query = $this->sQueryMySqlActiveDatabases($additionalFeatures);
181
                break;
182
            case 'Engines':
183
                $query = $this->sQueryMySqlActiveEngines($additionalFeatures);
184
                break;
185
            case 'Indexes':
186
                $query = $this->sQueryMySqlIndexes($additionalFeatures);
187
                break;
188
            case 'ServerTime':
189
                $query = $this->sQueryMySqlServerTime();
190
                break;
191
            case 'Statistics':
192
                $query = $this->sQueryMySqlStatistics($additionalFeatures);
193
                break;
194
            case 'Tables':
195
                $query = $this->sQueryMySqlTables($additionalFeatures);
196
                break;
197
            case 'VariablesGlobal':
198
                $query = $this->sQueryMySqlGlobalVariables();
199
                break;
200
        }
201
        return $this->setMySQLquery2Server($query, $returnType)['result'];
202
    }
203
204
    /**
205
     * Return the list of Tables from the MySQL server
206
     *
207
     * @return string
208
     */
209
    protected function getMySQLStatistics($filterArray = null)
210
    {
211
        return $this->getMySQLlistMultiple('Statistics', 'full_array_key_numbered', $filterArray);
212
    }
213
214
    /**
215
     * Return the list of Tables from the MySQL server
216
     *
217
     * @return string
218
     */
219
    protected function getMySQLlistTables($filterArray = null)
220
    {
221
        return $this->getMySQLlistMultiple('Tables', 'full_array_key_numbered', $filterArray);
222
    }
223
224
    /**
225
     * Provides a detection if given Query does contain a Parameter
226
     * that may require statement processing later on
227
     *
228
     * @param string $sQuery
229
     * @param string $paramIdentifier
230
     * @return boolean
231
     */
232
    protected function getMySQLqueryWithParameterIdentifier($sQuery, $paramIdentifier)
233
    {
234
        $sReturn = true;
235
        if (strpos($sQuery, $paramIdentifier) === false) {
236
            $sReturn = false;
237
        }
238
        return $sReturn;
239
    }
240
241
    /**
242
     * Return the time from the MySQL server
243
     *
244
     * @return string
245
     */
246
    protected function getMySQLserverTime()
247
    {
248
        return $this->getMySQLlistMultiple('ServerTime', 'value');
249
    }
250
251
    /**
252
     * Reads data from table into REQUEST super global
253
     *
254
     * @param string $tableName
255
     * @param array $filtersArray
256
     */
257
    protected function getRowDataFromTable($tableName, $filtersArray)
258
    {
259
        $query   = $this->sQueryRowsFromTable([$tableName, $this->setArrayToFilterValues($filtersArray)]);
260
        $rawData = $this->setMySQLquery2Server($query, 'array_pairs_key_value')['result'];
261
        if (!is_null($rawData)) {
262
            $this->initializeSprGlbAndSession();
263
            foreach ($rawData as $key => $value) {
264
                $vToSet = str_replace(['\\\\"', '\\"', "\\\\'", "\\'"], ['"', '"', "'", "'"], $value);
265
                $this->tCmnRequest->request->get($key, $vToSet);
266
            }
267
        }
268
    }
269
270
    /**
271
     * Transforms an array into usable filters
272
     *
273
     * @param array $entryArray
274
     * @param string $referenceTable
275
     * @return array
276
     */
277
    private function setArrayToFilterValues($entryArray, $referenceTable = '')
278
    {
279
        $filters = '';
280
        if ($referenceTable != '') {
281
            $referenceTable = '`' . $referenceTable . '`.';
282
        }
283
        foreach ($entryArray as $key => $value) {
284
            if (is_array($value)) {
285
                $filters2 = '';
286
                foreach ($value as $value2) {
287
                    if ($value2 != '') {
288
                        if ($filters2 != '') {
289
                            $filters2 .= ',';
290
                        }
291
                        $filters2 .= '"' . $value2 . '"';
292
                    }
293
                }
294
                if ($filters2 != '') {
295
                    if ($filters != '') {
296
                        $filters .= ' AND ';
297
                    }
298
                    $filters .= ' ' . $referenceTable . '`' . $key
299
                            . '` IN ("' . str_replace(',', '","', str_replace(["'", '"'], '', $filters2))
300
                            . '")';
301
                }
302
            } else {
303
                if (($filters != '') && (!in_array($value, ['', '%%']))) {
304
                    $filters .= ' AND ';
305
                }
306
                if (!in_array($value, ['', '%%'])) {
307
                    if ((substr($value, 0, 1) == '%') && (substr($value, -1) == '%')) {
308
                        $filters .= ' ' . $key . ' LIKE "' . $value . '"';
309
                    } else {
310
                        $filters .= ' ' . $key . ' = "' . $value . '"';
311
                    }
312
                }
313
            }
314
        }
315
        return $filters;
316
    }
317
318
    /**
319
     * Returns maximum length for a given MySQL field
320
     *
321
     * @param array $fieldDetails
322
     * @param boolean $outputFormated
323
     * @return array
324
     */
325
    protected function setFieldNumbers($fieldDetails, $outputFormated = false)
326
    {
327
        $sRtrn = $this->setFieldSpecific($fieldDetails);
328
        if ($outputFormated) {
329
            if (is_array($sRtrn)) {
330
                foreach ($sRtrn as $key => $value) {
331
                    $sRtrn[$key] = $this->setNumberFormat($value);
332
                }
333
            }
334
        }
335
        return $sRtrn;
336
    }
337
338
    private function setFieldSpecific($fieldDetails)
339
    {
340
        $sRtrn = '';
341
        if (in_array($fieldDetails['DATA_TYPE'], ['char', 'varchar', 'tinytext'])) {
342
            $sRtrn = ['M' => $fieldDetails['CHARACTER_MAXIMUM_LENGTH']];
343
        } elseif (in_array($fieldDetails['DATA_TYPE'], ['date'])) {
344
            $sRtrn = ['M' => 10];
345
        } elseif (in_array($fieldDetails['DATA_TYPE'], ['time'])) {
346
            $sRtrn = ['M' => 8];
347
        } elseif (in_array($fieldDetails['DATA_TYPE'], ['datetime', 'timestamp'])) {
348
            $sRtrn = ['M' => 19];
349
        } elseif (in_array($fieldDetails['DATA_TYPE'], ['decimal', 'numeric'])) {
350
            $sRtrn = ['M' => $fieldDetails['NUMERIC_PRECISION'], 'd' => $fieldDetails['NUMERIC_SCALE']];
351
        } elseif (in_array($fieldDetails['DATA_TYPE'], ['bigint', 'int', 'mediumint', 'smallint', 'tinyint'])) {
352
            $sRtrn = $this->setFldLmtsExact($fieldDetails['DATA_TYPE']);
353
        }
354
        return $sRtrn;
355
    }
356
357
    private function setFldLmts($colType, $loLmt, $upLmt, $szN, $szUS)
358
    {
359
        $aReturn = ['m' => $loLmt, 'M' => $upLmt, 'l' => $szN];
360
        if (strpos($colType, 'unsigned') !== false) {
361
            $aReturn = ['m' => 0, 'M' => ($upLmt - $loLmt), 'l' => $szUS];
362
        }
363
        return $aReturn;
364
    }
365
366
    private function setFldLmtsExact($cTp)
367
    {
368
        $xct     = [
369
            'bigint'    => ['l' => -9223372036854775808, 'L' => 9223372036854775807, 's' => 21, 'sUS' => 20],
370
            'int'       => ['l' => -2147483648, 'L' => 2147483647, 's' => 11, 'sUS' => 10],
371
            'mediumint' => ['l' => -8388608, 'L' => 8388607, 's' => 9, 'sUS' => 8],
372
            'smallint'  => ['l' => -32768, 'L' => 32767, 's' => 6, 'sUS' => 5],
373
            'tinyint'   => ['l' => -128, 'L' => 127, 's' => 4, 'sUS' => 3],
374
        ];
375
        $sReturn = null;
376
        if (array_key_exists($cTp, $xct)) {
377
            $sReturn = $this->setFldLmts($cTp, $xct[$cTp]['l'], $xct[$cTp]['L'], $xct[$cTp]['s'], $xct[$cTp]['sUS']);
378
        }
379
        return $sReturn;
380
    }
381
382
    /**
383
     * Transmit Query to MySQL server and get results back
384
     *
385
     * @param string $sQuery
386
     * @param string $sReturnType
387
     * @param array $ftrs
388
     * @return boolean|array|string
389
     */
390
    protected function setMySQLquery2Server($sQuery, $sReturnType = null, $ftrs = null)
391
    {
392
        $aReturn = [
393
            'customError' => '',
394
            'result'      => null
395
        ];
396
        if (is_null($sReturnType)) {
397
            return $this->mySQLconnection->query(html_entity_decode($sQuery));
398
        } elseif (is_null($this->mySQLconnection)) {
399
            $aReturn['customError'] = $this->lclMsgCmn('i18n_MySQL_ConnectionNotExisting');
400
        } else {
401
            $result = $this->mySQLconnection->query(html_entity_decode($sQuery));
402
            if ($result) {
403
                switch (strtolower($sReturnType)) {
404
                    case 'array_first_key_rest_values':
405
                    case 'array_key_value':
406
                    case 'array_key_value2':
407
                    case 'array_key2_value':
408
                    case 'array_numbered':
409
                    case 'array_pairs_key_value':
410 View Code Duplication
                    case 'full_array_key_numbered':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
411
                        $aReturn           = $this->setMySQLquery2ServerByPattern([
412
                            'NoOfColumns' => $result->field_count,
413
                            'NoOfRows'    => $result->num_rows,
414
                            'QueryResult' => $result,
415
                            'returnType'  => $sReturnType,
416
                            'return'      => $aReturn
417
                        ]);
418
                        break;
419
                    case 'full_array_key_numbered_with_record_number_prefix':
420 View Code Duplication
                    case 'full_array_key_numbered_with_prefix':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
421
                        $aReturn           = $this->setMySQLquery2ServerByPattern([
422
                            'NoOfColumns' => $result->field_count,
423
                            'NoOfRows'    => $result->num_rows,
424
                            'QueryResult' => $result,
425
                            'returnType'  => $sReturnType,
426
                            'prefix'      => $ftrs['prefix'],
427
                            'return'      => $aReturn
428
                        ]);
429
                        break;
430
                    case 'id':
431
                        $aReturn['result'] = $this->mySQLconnection->insert_id;
432
                        break;
433
                    case 'lines':
434
                        $aReturn['result'] = $result->num_rows;
435
                        break;
436
                    case 'value':
437
                        if (($result->num_rows == 1) && ($result->field_count == 1)) {
438
                            $aReturn['result'] = $result->fetch_row()[0];
439
                        } else {
440
                            $msg                    = $this->lclMsgCmn('i18n_MySQL_QueryResultExpected1ResultedOther');
441
                            $aReturn['customError'] = sprintf($msg, $result->num_rows);
442
                        }
443
                        break;
444
                    default:
445
                        $msg                    = $this->lclMsgCmn('i18n_MySQL_QueryInvalidReturnTypeSpecified');
446
                        $aReturn['customError'] = sprintf($msg, $sReturnType, __FUNCTION__);
447
                        break;
448
                }
449
                if (is_object($result)) {
450
                    $result->close();
451
                }
452
            } else {
453
                $erNo                   = $this->mySQLconnection->errno;
454
                $erMsg                  = $this->mySQLconnection->error;
455
                $aReturn['customError'] = sprintf($this->lclMsgCmn('i18n_MySQL_QueryError'), $erNo, $erMsg);
456
            }
457
        }
458
        return $aReturn;
459
    }
460
461
    /**
462
     * Turns a raw query result into various structures
463
     * based on different predefined $parameters['returnType'] value
464
     *
465
     * @param array $parameters
466
     * @return array as ['customError' => '...', 'result' => '...']
467
     */
468
    protected function setMySQLquery2ServerByPattern($parameters)
469
    {
470
        $aReturn    = $parameters['return'];
471
        $buildArray = false;
472
        switch ($parameters['returnType']) {
473 View Code Duplication
            case 'array_first_key_rest_values':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
474
                if ($parameters['NoOfColumns'] >= 2) {
475
                    $buildArray = true;
476
                } else {
477
                    $msg                    = $this->lclMsgCmn('QueryResultExpectedAtLeast2ColsResultedOther');
478
                    $aReturn['customError'] = sprintf($msg, $parameters['NoOfColumns']);
479
                }
480
                break;
481
            case 'array_key_value':
482
            case 'array_key_value2':
483 View Code Duplication
            case 'array_key2_value':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
484
                if ($parameters['NoOfColumns'] == 2) {
485
                    $buildArray = true;
486
                } else {
487
                    $msg                    = $this->lclMsgCmn('i18n_MySQL_QueryResultExpected2ColumnsResultedOther');
488
                    $aReturn['customError'] = sprintf($msg, $parameters['NoOfColumns']);
489
                }
490
                break;
491 View Code Duplication
            case 'array_numbered':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
492
                if ($parameters['NoOfColumns'] == 1) {
493
                    $buildArray = true;
494
                } else {
495
                    $msg                    = $this->lclMsgCmn('i18n_MySQL_QueryResultExpected1ColumnResultedOther');
496
                    $aReturn['customError'] = sprintf($msg, $parameters['NoOfColumns']);
497
                }
498
                break;
499
            case 'array_pairs_key_value':
500
                if (($parameters['NoOfRows'] == 1) && ($parameters['NoOfColumns'] > 1)) {
501
                    $buildArray = true;
502
                } else {
503
                    $shorterLclString       = 'i18n_MySQL_QueryResultExpected1RowManyColumnsResultedOther';
504
                    $msg                    = $this->lclMsgCmn($shorterLclString);
505
                    $aReturn['customError'] = sprintf($msg, $parameters['NoOfRows'], $parameters['NoOfColumns']);
506
                }
507
                break;
508
            case 'full_array_key_numbered':
509
            case 'full_array_key_numbered_with_prefix':
510
            case 'full_array_key_numbered_with_record_number_prefix':
511
                if ($parameters['NoOfColumns'] == 0) {
512
                    $aReturn['customError'] = $this->lclMsgCmn('i18n_MySQL_QueryResultExpected1OrMoreRows0Resulted');
513
                    if (in_array($parameters['returnType'], [
514
                                'full_array_key_numbered_with_prefix',
515
                                'full_array_key_numbered_with_record_number_prefix',
516
                            ])) {
517
                        $aReturn['result'][$parameters['prefix']] = null;
518
                    }
519
                } else {
520
                    $buildArray = true;
521
                }
522
                break;
523
            default:
524
                $aReturn['customError'] = $parameters['returnType'] . ' is not defined!';
525
                break;
526
        }
527
        if ($buildArray) {
528
            $counter2 = 0;
529
            for ($counter = 0; $counter < $parameters['NoOfRows']; $counter++) {
530
                $line = $parameters['QueryResult']->fetch_row();
531
                switch ($parameters['returnType']) {
532
                    case 'array_first_key_rest_values':
533
                        $finfo         = $parameters['QueryResult']->fetch_fields();
534
                        $columnCounter = 0;
535
                        foreach ($finfo as $value) {
536
                            if ($columnCounter != 0) {
537
                                $aReturn['result'][$line[0]][$value->name] = $line[$columnCounter];
538
                            }
539
                            $columnCounter++;
540
                        }
541
                        break;
542
                    case 'array_key_value':
543
                        $aReturn['result'][$line[0]]                  = $line[1];
544
                        break;
545
                    case 'array_key_value2':
546
                        $aReturn['result'][$line[0]][]                = $line[1];
547
                        break;
548
                    case 'array_key2_value':
549
                        $aReturn['result'][$line[0] . '@' . $line[1]] = $line[1];
550
                        break;
551
                    case 'array_numbered':
552
                        $aReturn['result'][]                          = $line[0];
553
                        break;
554
                    case 'array_pairs_key_value':
555
                        $finfo                                        = $parameters['QueryResult']->fetch_fields();
556
                        $columnCounter                                = 0;
557
                        foreach ($finfo as $value) {
558
                            $aReturn['result'][$value->name] = $line[$columnCounter];
559
                            $columnCounter++;
560
                        }
561
                        break;
562
                    case 'full_array_key_numbered':
563
                        $finfo         = $parameters['QueryResult']->fetch_fields();
564
                        $columnCounter = 0;
565
                        foreach ($finfo as $value) {
566
                            $aReturn['result'][$counter2][$value->name] = $line[$columnCounter];
567
                            $columnCounter++;
568
                        }
569
                        $counter2++;
570
                        break;
571
                    case 'full_array_key_numbered_with_record_number_prefix':
572
                        $parameters['prefix'] = 'RecordNo';
573
                    // intentionally left open
574
                    case 'full_array_key_numbered_with_prefix':
575
                        $finfo                = $parameters['QueryResult']->fetch_fields();
576
                        $columnCounter        = 0;
577
                        foreach ($finfo as $value) {
578
                            $aReturn['result'][$parameters['prefix']][$counter2][$value->name] = $line[$columnCounter];
579
                            $columnCounter++;
580
                        }
581
                        $counter2++;
582
                        break;
583
                }
584
            }
585
        }
586
        return $aReturn;
587
    }
588
}
589