Completed
Push — work-fleets ( 98be23...4e14e1 )
by SuperNova.WS
05:25
created

db_mysql_v5::mysql_prepare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * User: Gorlum
5
 * Date: 02.09.2015
6
 * Time: 0:41
7
 */
8
class db_mysql_v5 {
9
  const DB_MYSQL_TRANSACTION_SERIALIZABLE = 'SERIALIZABLE';
10
  const DB_MYSQL_TRANSACTION_REPEATABLE_READ = 'REPEATABLE READ';
11
  const DB_MYSQL_TRANSACTION_READ_COMMITTED = 'READ COMMITTED';
12
  const DB_MYSQL_TRANSACTION_READ_UNCOMMITTED = 'READ UNCOMMITTED';
13
14
  /**
15
   * Соединение с MySQL
16
   *
17
   * @var mysqli $link
18
   */
19
  public $link;
20
  /**
21
   * Статус соеднения с MySQL
22
   *
23
   * @var bool
24
   */
25
  public $connected = false;
26
27
  // public $dbsettings = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
28
29
  function mysql_connect($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...
30
    static $need_keys = array('server', 'user', 'pass', 'name', 'prefix');
31
32
    if ($this->connected) {
33
      return true;
34
    }
35
36 View Code Duplication
    if (empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) {
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...
37
      classSupernova::$debug->error_fatal('There is missconfiguration in your config.php. Check it again');
38
    }
39
40
    @$this->link = mysqli_connect($settings['server'], $settings['user'], $settings['pass'], $settings['name']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
41
    if (!is_object($this->link) || $this->link->connect_error) {
42
      classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #' . $this->link->connect_errno, $this->link->connect_error);
43
    }
44
45
46
    !$this->mysql_query("/*!40101 SET NAMES 'utf8' */")
47
      ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #' . $this->link->errno, $this->link->error)
48
      : false;
49
    !$this->mysql_query("SET NAMES 'utf8';")
50
      ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #' . $this->link->errno, $this->link->error)
51
      : false;
52
53
    !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';')
54
      ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #' . $this->link->errno, $this->link->error)
55
      : false;
56
57
    $this->connected = true;
58
59
    return true;
60
  }
61
62
  /**
63
   * L0 perform the query
64
   *
65
   * @param $query_string
66
   *
67
   * @return bool|mysqli_result
68
   */
69
  function mysql_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...
70
    return $this->link->query($query_string);
71
  }
72
73
  /**
74
   * L0 fetch assoc array
75
   *
76
   * @param $query
77
   *
78
   * @return array|null
79
   */
80
  function mysql_fetch_assoc(&$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...
81
    return mysqli_fetch_assoc($query);
82
  }
83
84
  function mysql_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...
85
    return mysqli_fetch_row($query);
86
  }
87
88
  function mysql_real_escape_string($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...
89
    return mysqli_real_escape_string($this->link, $unescaped_string);
90
  }
91
92
  function mysql_close_link() {
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...
93
    if (is_object($this->link)) {
94
      $this->link->close();
95
      $this->connected = false;
96
      unset($this->link);
97
    }
98
99
    return true;
100
  }
101
102
  function mysql_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...
103
    return mysqli_error($this->link);
104
  }
105
106
  function mysql_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...
107
    return mysqli_insert_id($this->link);
108
  }
109
110
  function mysql_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...
111
    return mysqli_num_rows($result);
112
  }
113
114
  function mysql_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...
115
    return mysqli_affected_rows($this->link);
116
  }
117
118
  function mysql_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...
119
    return mysqli_get_client_info();
120
  }
121
122
  function mysql_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...
123
    return mysqli_get_server_info($this->link);
124
  }
125
126
  function mysql_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...
127
    return mysqli_get_host_info($this->link);
128
  }
129
130
  function mysql_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...
131
    return mysqli_stat($this->link);
132
  }
133
134
  /**
135
   * @param string $statement
136
   *
137
   * @return bool|mysqli_stmt
138
   */
139
  function mysql_prepare($statement) {
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...
140
    return mysqli_prepare($this->link, $statement);
141
  }
142
143
}
144