| @@ -1,65 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -function acym_getTables(bool $reload = false): array | |
| 4 | -{ | |
| 5 | - static $tables = null; | |
| 6 | - if (empty($tables) || $reload) { | |
| 7 | - $tables = acym_loadResultArray('SHOW TABLES'); | |
| 8 | - } | |
| 9 | - | |
| 10 | - return $tables; | |
| 11 | -} | |
| 12 | - | |
| 13 | -function acym_getColumns(string $table, bool $acyTable = true, bool $addPrefix = true): array | |
| 14 | -{ | |
| 15 | - if ($addPrefix) { | |
| 16 | - $prefix = $acyTable ? '#__acym_' : '#__'; | |
| 17 | - $table = $prefix.$table; | |
| 18 | - } | |
| 19 | - | |
| 20 | - static $columns = []; | |
| 21 | - if (empty($columns[$table])) { | |
| 22 | - $columns[$table] = acym_loadResultArray('SHOW COLUMNS FROM '.acym_secureDBColumn($table)); | |
| 23 | - } | |
| 24 | - | |
| 25 | - return $columns[$table] ?? []; | |
| 26 | -} | |
| 27 | - | |
| 28 | -function acym_secureDBColumn(string $fieldName): string | |
| 29 | -{ | |
| 30 | - if (preg_match('|[^a-z0-9#_.-]|i', $fieldName) !== 0) { | |
| 31 | - die('field, table or database "'.acym_escape($fieldName).'" not secured'); | |
| 32 | - } | |
| 33 | - | |
| 34 | - return $fieldName; | |
| 35 | -} | |
| 36 | - | |
| 37 | -function acym_getDatabases(): array | |
| 38 | -{ | |
| 39 | - try { | |
| 40 | - $allDatabases = acym_loadResultArray('SHOW DATABASES'); | |
| 41 | - } catch (Exception $exception) { | |
| 42 | - $allDatabases = []; | |
| 43 | - $allDatabases[] = acym_loadResult('SELECT DATABASE();'); | |
| 44 | - } | |
| 45 | - | |
| 46 | - $databases = []; | |
| 47 | - foreach ($allDatabases as $database) { | |
| 48 | - $databases[$database] = $database; | |
| 49 | - } | |
| 50 | - | |
| 51 | - return $databases; | |
| 52 | -} | |
| 53 | - | |
| 54 | -function acym_addLimit(string &$query, int $limit = 1, ?int $offset = null): void | |
| 55 | -{ | |
| 56 | - if (strpos($query, 'LIMIT ') !== false) { | |
| 57 | - return; | |
| 58 | - } | |
| 59 | - | |
| 60 | - $query .= ' LIMIT '; | |
| 61 | - if (!empty($offset)) { | |
| 62 | - $query .= intval($offset).','; | |
| 63 | - } | |
| 64 | - $query .= intval($limit); | |
| 65 | -} | |