|
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(); |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
function mysql_connect($settings) { |
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
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']); |
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
81
|
|
|
return mysqli_fetch_assoc($query); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
function mysql_fetch_row(&$query) { |
|
|
|
|
|
|
85
|
|
|
return mysqli_fetch_row($query); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
function mysql_real_escape_string($unescaped_string) { |
|
|
|
|
|
|
89
|
|
|
return mysqli_real_escape_string($this->link, $unescaped_string); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
function mysql_close_link() { |
|
|
|
|
|
|
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() { |
|
|
|
|
|
|
103
|
|
|
return mysqli_error($this->link); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
function mysql_insert_id() { |
|
|
|
|
|
|
107
|
|
|
return mysqli_insert_id($this->link); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
function mysql_num_rows(&$result) { |
|
|
|
|
|
|
111
|
|
|
return mysqli_num_rows($result); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
function mysql_affected_rows() { |
|
|
|
|
|
|
115
|
|
|
return mysqli_affected_rows($this->link); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
function mysql_get_client_info() { |
|
|
|
|
|
|
119
|
|
|
return mysqli_get_client_info(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function mysql_get_server_info() { |
|
|
|
|
|
|
123
|
|
|
return mysqli_get_server_info($this->link); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
function mysql_get_host_info() { |
|
|
|
|
|
|
127
|
|
|
return mysqli_get_host_info($this->link); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
function mysql_stat() { |
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
140
|
|
|
return mysqli_prepare($this->link, $statement); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
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.