Test Failed
Branch trunk (412648)
by SuperNova.WS
03:40
created

db_mysql::mysql_get_fields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use Common\GlobalContainer;
4
5
/**
6
 * User: Gorlum
7
 * Date: 01.09.2015
8
 * Time: 15:58
9
 */
10
class db_mysql {
11
  const DB_MYSQL_TRANSACTION_SERIALIZABLE = 'SERIALIZABLE';
12
  const DB_MYSQL_TRANSACTION_REPEATABLE_READ = 'REPEATABLE READ';
13
  const DB_MYSQL_TRANSACTION_READ_COMMITTED = 'READ COMMITTED';
14
  const DB_MYSQL_TRANSACTION_READ_UNCOMMITTED = 'READ UNCOMMITTED';
15
16
  /**
17
   * Статус соеднения с MySQL
18
   *
19
   * @var bool
20
   */
21
  public $connected = false;
22
  /**
23
   * Префикс названий таблиц в БД
24
   *
25
   * @var string
26
   */
27
  public $db_prefix = '';
28
  /**
29
   * Настройки БД
30
   *
31
   * @var array
32
   */
33
  protected $dbsettings = array();
34
  /**
35
   * Драйвер для прямого обращения к MySQL
36
   *
37
   * @var db_mysql_v5 $driver
38
   */
39
  public $driver = null;
40
41
  /**
42
   * Общее время запросов
43
   *
44
   * @var float $time_mysql_total
45
   */
46
  public $time_mysql_total = 0.0;
47
48
  /**
49
   * DB schemes
50
   *
51
   * @var \DBAL\Schema|null $schema
52
   */
53
  protected static $schema = null;
54
55
  /**
56
   * db_mysql constructor.
57
   *
58
   * @param GlobalContainer $gc
59
   */
60
  public function __construct($gc) {
0 ignored issues
show
Unused Code introduced by
The parameter $gc is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
//    $this->transaction = new \DBAL\DbTransaction($gc, $this);
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
//    $this->snCache = new $gc->snCacheClass($gc, $this);
63
//    $this->operator = new DbRowDirectOperator($this);
64
  }
65
66
  public function schema() {
67
    if(!isset(self::$schema)) {
68
      self::$schema = new \DBAL\Schema($this);
69
    }
70
71
    return self::$schema;
72
  }
73
74
  function load_db_settings() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
75
    $dbsettings = array();
76
77
    require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX);
78
79
    $this->dbsettings = $dbsettings;
80
  }
81
82
  function sn_db_connect($external_db_settings = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
    $this->db_disconnect();
84
85
    if(!empty($external_db_settings) && is_array($external_db_settings)) {
86
      $this->dbsettings = $external_db_settings;
87
    }
88
89
    if(empty($this->dbsettings)) {
90
      $this->load_db_settings();
91
    }
92
93
    // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны
94
    if(!empty($this->dbsettings)) {
95
      $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver'];
96
      $this->driver = new $driver_name();
97
      $this->db_prefix = $this->dbsettings['prefix'];
98
99
      $this->connected = $this->connected || $this->driver_connect();
100
101
      if($this->connected && empty($this->schema()->getSnTables())) {
102
        die('DB error - cannot find any table. Halting...');
103
      }
104
    } else {
105
      $this->connected = false;
106
    }
107
108
    return $this->connected;
109
  }
110
111
  function driver_connect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
112
    global $debug;
113
114
    if(!is_object($this->driver)) {
115
      $debug->error_fatal('DB Error - No driver for MySQL found!');
116
    }
117
118
    if(!method_exists($this->driver, 'mysql_connect')) {
119
      $debug->error_fatal('DB Error - WRONG MySQL driver!');
120
    }
121
122
    return $this->driver->mysql_connect($this->dbsettings);
123
  }
124
125
  function db_disconnect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
126
    if($this->connected) {
127
      $this->connected = !$this->driver_disconnect();
128
      $this->connected = false;
129
    }
130
131
    return !$this->connected;
132
  }
133
134
  function doquery($query, $table = '', $fetch = false, $skip_query_check = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
135
    global $numqueries, $debug, $sn_cache, $config;
136
137
    if(!is_string($table)) {
138
      $fetch = $table;
139
    }
140
141
    if(!$this->connected) {
142
      $this->sn_db_connect();
143
    }
144
145
    $query = trim($query);
146
    $this->security_watch_user_queries($query);
147
    $skip_query_check or $this->security_query_check_bad_words($query);
148
149
    $sql = $query;
150
    if(strpos($sql, '{{') !== false) {
151
      foreach($this->schema()->getSnTables() as $tableName) {
0 ignored issues
show
Bug introduced by
The expression $this->schema()->getSnTables() of type null|array<integer,string> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
152
        $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql);
153
      }
154
    }
155
156
    if($config->debug) {
157
      $numqueries++;
158
      $arr = debug_backtrace();
159
      $file = end(explode('/',$arr[0]['file']));
0 ignored issues
show
Bug introduced by
explode('/', $arr[0]['file']) cannot be passed to end() as the parameter $array expects a reference.
Loading history...
160
      $line = $arr[0]['line'];
161
      $debug->add("<tr><th>Query $numqueries: </th><th>$query</th><th>$file($line)</th><th>$table</th><th>$fetch</th></tr>");
162
    }
163
164
    if(defined('DEBUG_SQL_COMMENT')) {
165
      $backtrace = debug_backtrace();
166
      $sql_comment = $debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG'));
167
168
      $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql);
169
      if(defined('DEBUG_SQL_ONLINE')) {
170
        $debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL);
171
      }
172
173
      if(defined('DEBUG_SQL_ERROR')) {
174
        array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql));
175
        $debug->add_to_array($sql_comment);
176
        // $debug->add_to_array($sql_comment . preg_replace("/\s+/", ' ', $sql));
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
177
      }
178
      $sql = $sql_commented;
179
    }
180
181
    $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error()."<br />$sql<br />",'SQL Error');
182
183
    return $fetch ? $this->db_fetch($sqlquery) : $sqlquery;
184
  }
185
186
  /**
187
   * @param \DBAL\DbQuery $dbQuery
188
   *
189
   * @return array|null
190
   */
191
  public function dbqSelectAndFetch(\DBAL\DbQuery $dbQuery) {
192
    return $this->doquery($dbQuery->select(), true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
193
  }
194
195
196
  function security_watch_user_queries($query) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
197
    // TODO Заменить это на новый логгер
198
    global $config, $is_watching, $user, $debug;
199
200
    if(!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array))
201
    {
202
      if(!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) {
203
        $is_watching = true;
204
        $msg = "\$query = \"{$query}\"\n\r";
205
        if(!empty($_POST)) {
206
          $msg .= "\n\r" . dump($_POST,'$_POST');
207
        }
208
        if(!empty($_GET)) {
209
          $msg .= "\n\r" . dump($_GET,'$_GET');
210
        }
211
        $debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true));
212
        $is_watching = false;
213
      }
214
    }
215
  }
216
217
218
  function security_query_check_bad_words($query) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
219
    global $user, $dm_change_legit, $mm_change_legit;
220
221
    switch(true) {
222
      case stripos($query, 'RUNCATE TABL') != false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'RUNCATE TABL') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
223
      case stripos($query, 'ROP TABL') != false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'ROP TABL') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
224
      case stripos($query, 'ENAME TABL') != false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'ENAME TABL') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
225
      case stripos($query, 'REATE DATABAS') != false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'REATE DATABAS') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
226
      case stripos($query, 'REATE TABL') != false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'REATE TABL') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
227
      case stripos($query, 'ET PASSWOR') != false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'ET PASSWOR') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
228
      case stripos($query, 'EOAD DAT') != false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'EOAD DAT') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
229
      case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'RPG_POINTS') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
230
      case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'METAMATTER') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
231
      case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stripos($query, 'AUTHLEVEL') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
232
        $report  = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n";
233
        $report .= ">Database Inforamation\n";
234
        $report .= "\tID - ".$user['id']."\n";
235
        $report .= "\tUser - ".$user['username']."\n";
236
        $report .= "\tAuth level - ".$user['authlevel']."\n";
237
        $report .= "\tAdmin Notes - ".$user['adminNotes']."\n";
238
        $report .= "\tCurrent Planet - ".$user['current_planet']."\n";
239
        $report .= "\tUser IP - ".$user['user_lastip']."\n";
240
        $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n";
241
        $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n";
242
        $report .= "\tCurrent Page - ".$user['current_page']."\n";
243
        $report .= "\tRegister Time - ".$user['register_time']."\n";
244
        $report .= "\n";
245
246
        $report .= ">Query Information\n";
247
        $report .= "\tQuery - ".$query."\n";
248
        $report .= "\n";
249
250
        $report .= ">\$_SERVER Information\n";
251
        $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n";
252
        $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n";
253
        $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n";
254
        $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n";
255
        $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n";
256
        $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n";
257
        $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n";
258
        $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n";
259
260
        $report .= "\n--------------------------------------------------------------------------------------------------\n";
261
262
        $fp = fopen(SN_ROOT_PHYSICAL . 'badqrys.txt', 'a');
263
        fwrite($fp, $report);
0 ignored issues
show
Security File Manipulation introduced by
$report can contain request data and is used in file manipulation context(s) leading to a potential security vulnerability.

5 paths for user data to reach this point

  1. Path: Fetching key HTTP_REFERER from $_SERVER, and $report is assigned in classes/db_mysql.php on line 255
  1. Fetching key HTTP_REFERER from $_SERVER, and $report is assigned
    in classes/db_mysql.php on line 255
  2. Path: Fetching key HTTP_USER_AGENT from $_SERVER, and $report is assigned in classes/db_mysql.php on line 253
  1. Fetching key HTTP_USER_AGENT from $_SERVER, and $report is assigned
    in classes/db_mysql.php on line 253
  2. $report is assigned
    in classes/db_mysql.php on line 255
  3. Path: Fetching key HTTP_HOST from $_SERVER, and $report is assigned in classes/db_mysql.php on line 252
  1. Fetching key HTTP_HOST from $_SERVER, and $report is assigned
    in classes/db_mysql.php on line 252
  2. $report is assigned
    in classes/db_mysql.php on line 253
  3. $report is assigned
    in classes/db_mysql.php on line 255
  4. Path: Read from $_POST in includes/general.php on line 287
  1. Read from $_POST
    in includes/general.php on line 287
  2. sys_get_param() returns tainted data, and $value is assigned
    in includes/general.php on line 292
  3. sys_get_param_id() returns tainted data, and $fleetid is assigned
    in includes/includes/flt_page4.inc on line 7
  4. ``'INSERT INTO {{aks}} SET `name` = \'' . db_escape($lang['flt_acs_prefix'] . $fleetid) . '\', `teilnehmer` = \'' . $user['id'] . '\', `flotten` = \'' . $fleetid . '\', `ankunft` = \'' . $fleet['fleet_start_time'] . '\', `galaxy` = \'' . $fleet['fleet_end_galaxy'] . '\', `system` = \'' . $fleet['fleet_end_system'] . '\', `planet` = \'' . $fleet['fleet_end_planet'] . '\', `planet_type` = \'' . $fleet['fleet_end_type'] . '\', `eingeladen` = \'' . $user['id'] . '\', `fleet_end_time` = \'' . $fleet['fleet_end_time'] . '\''`` is passed to doquery()
    in includes/includes/flt_page4.inc on line 52
  5. $query is passed to db_mysql::doquery()
    in includes/db.php on line 102
  6. $query is passed through trim(), and $query is assigned
    in classes/db_mysql.php on line 145
  7. $query is passed to db_mysql::security_query_check_bad_words()
    in classes/db_mysql.php on line 147
  8. $report is assigned
    in classes/db_mysql.php on line 247
  9. $report is assigned
    in classes/db_mysql.php on line 252
  10. $report is assigned
    in classes/db_mysql.php on line 253
  11. $report is assigned
    in classes/db_mysql.php on line 255
  5. Path: Fetching key HTTP_USER_AGENT from $_SERVER, and $report is assigned in classes/db_mysql.php on line 241
  1. Fetching key HTTP_USER_AGENT from $_SERVER, and $report is assigned
    in classes/db_mysql.php on line 241
  2. $report is assigned
    in classes/db_mysql.php on line 247
  3. $report is assigned
    in classes/db_mysql.php on line 252
  4. $report is assigned
    in classes/db_mysql.php on line 253
  5. $report is assigned
    in classes/db_mysql.php on line 255

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
264
        fclose($fp);
265
266
        $message = 'Привет, я не знаю то, что Вы пробовали сделать, но команда, которую Вы только послали базе данных, не выглядела очень дружественной и она была заблокированна.<br /><br />Ваш IP, и другие данные переданны администрации сервера. Удачи!.';
267
        die($message);
268
        break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
269
    }
270
  }
271
272
  function mysql_get_table_list() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
273
    return $this->db_sql_query('SHOW TABLES;');
274
  }
275
  function mysql_get_innodb_status() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
276
    return $this->db_sql_query('SHOW ENGINE INNODB STATUS;');
277
  }
278
279
  /**
280
   * @param string $tableName_unsafe
281
   *
282
   * @return array[]
283
   */
284
  public function mysql_get_fields($tableName_unsafe) {
285
    $result = [];
286
287
    $prefixedTableName_safe = $this->db_escape($this->db_prefix . $tableName_unsafe);
288
    $q1 = $this->db_sql_query("SHOW FULL COLUMNS FROM `{$prefixedTableName_safe}`;");
289
    while($r1 = db_fetch($q1)) {
290
      $result[$r1['Field']] = $r1;
291
    }
292
    return $result;
293
  }
294
295
  /**
296
   * @param string $tableName_unsafe
297
   *
298
   * @return array[]
299
   */
300
  public function mysql_get_indexes($tableName_unsafe) {
301
    $result = [];
302
303
    $prefixedTableName_safe = $this->db_escape($this->db_prefix . $tableName_unsafe);
304
    $q1 = $this->db_sql_query("SHOW INDEX FROM {$prefixedTableName_safe};");
305
    while($r1 = db_fetch($q1)) {
306
      $indexName = $r1['Key_name'];
307
308
      $result[$indexName]['name'] = $r1['Key_name'];
309
      $result[$indexName]['signature'][] = $r1['Column_name'];
310
      $result[$indexName]['fields'][$r1['Column_name']] = $r1;
311
    }
312
313
    foreach ($result as &$indexDescription) {
314
      $indexDescription['signature'] = implode(',', $indexDescription['signature']);
315
    }
316
317
    return $result;
318
  }
319
320
  /**
321
   * @param string $tableName_unsafe
322
   *
323
   * @return array[]
324
   */
325
  public function mysql_get_constraints($tableName_unsafe) {
326
    $result = [];
327
328
    $prefixedTableName_safe = $this->db_escape($this->db_prefix . $tableName_unsafe);
329
330
    $q1 = $this->db_sql_query("SELECT * FROM `information_schema`.`KEY_COLUMN_USAGE` WHERE `TABLE_SCHEMA` = '" . db_escape(classSupernova::$db_name). "' AND `TABLE_NAME` = '{$prefixedTableName_safe}' AND `REFERENCED_TABLE_NAME` IS NOT NULL;");
331
    while($r1 = db_fetch($q1)) {
332
      $indexName = $r1['CONSTRAINT_NAME'];
333
334
      $table_referenced = str_replace($this->db_prefix, '', $r1['REFERENCED_TABLE_NAME']);
335
336
      $result[$indexName]['name'] = $indexName;
337
      $result[$indexName]['signature'][] = "{$r1['COLUMN_NAME']}=>{$table_referenced}.{$r1['REFERENCED_COLUMN_NAME']}";
338
      $r1['REFERENCED_TABLE_NAME'] = $table_referenced;
339
      $r1['TABLE_NAME'] = $tableName_unsafe;
340
      $result[$indexName]['fields'][$r1['COLUMN_NAME']] = $r1;
341
    }
342
343
    foreach ($result as &$constraint) {
344
      $constraint['signature'] = implode(',', $constraint['signature']);
345
    }
346
347
    return $result;
348
  }
349
350
351 View Code Duplication
  function db_sql_query($query_string) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
352
    $microtime = microtime(true);
353
    $result = $this->driver->mysql_query($query_string);
354
    $this->time_mysql_total += microtime(true) - $microtime;
355
    return $result;
356
//    return $this->driver->mysql_query($query_string);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
357
  }
358
359
  /**
360
   * @param mysqli_result $query_result
361
   *
362
   * @return array|null
363
   */
364 View Code Duplication
  function db_fetch(&$query_result) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
365
    $microtime = microtime(true);
366
    $result = $this->driver->mysql_fetch_assoc($query_result);
367
    $this->time_mysql_total += microtime(true) - $microtime;
368
    return $result;
369
//    return $this->driver->mysql_fetch_assoc($query);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
370
  }
371
  function db_fetch_row(&$query) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
372
    return $this->driver->mysql_fetch_row($query);
373
  }
374
  function db_escape($unescaped_string) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
375
    return $this->driver->mysql_real_escape_string($unescaped_string);
376
  }
377
  function driver_disconnect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
378
    return $this->driver->mysql_close_link();
379
  }
380
  function db_error() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
381
    return $this->driver->mysql_error();
382
  }
383
  function db_insert_id() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
384
    return $this->driver->mysql_insert_id();
385
  }
386
  function db_num_rows(&$result) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
387
    return $this->driver->mysql_num_rows($result);
388
  }
389
  function db_affected_rows() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
390
    return $this->driver->mysql_affected_rows();
391
  }
392
  function db_get_client_info() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
393
    return $this->driver->mysql_get_client_info();
394
  }
395
  function db_get_server_info() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
396
    return $this->driver->mysql_get_server_info();
397
  }
398
  function db_get_host_info() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
399
    return $this->driver->mysql_get_host_info();
400
  }
401
  function db_get_server_stat() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
402
    return $this->driver->mysql_stat();
403
  }
404
405
}
406