1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DBAL; |
4
|
|
|
/** |
5
|
|
|
* User: Gorlum |
6
|
|
|
* Date: 02.09.2015 |
7
|
|
|
* Time: 0:41 |
8
|
|
|
*/ |
9
|
|
|
class db_mysql_v4 { |
10
|
|
|
const DB_MYSQL_TRANSACTION_SERIALIZABLE = 'SERIALIZABLE'; |
11
|
|
|
const DB_MYSQL_TRANSACTION_REPEATABLE_READ = 'REPEATABLE READ'; |
12
|
|
|
const DB_MYSQL_TRANSACTION_READ_COMMITTED = 'READ COMMITTED'; |
13
|
|
|
const DB_MYSQL_TRANSACTION_READ_UNCOMMITTED = 'READ UNCOMMITTED'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Соединение с MySQL |
17
|
|
|
* |
18
|
|
|
* @var resource $link |
19
|
|
|
*/ |
20
|
|
|
public $link; |
21
|
|
|
/** |
22
|
|
|
* Статус соеднения с MySQL |
23
|
|
|
* |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
public $connected = false; |
27
|
|
|
|
28
|
|
|
// public $dbsettings = array(); |
|
|
|
|
29
|
|
|
|
30
|
|
|
public function mysql_connect($settings) { |
31
|
|
|
global $debug; |
|
|
|
|
32
|
|
|
|
33
|
|
|
static $need_keys = array('server', 'user', 'pass', 'name', 'prefix'); |
34
|
|
|
|
35
|
|
|
if ($this->connected) { |
36
|
|
|
return true; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) { |
40
|
|
|
$debug->error_fatal('There is missconfiguration in your config.php. Check it again', $this->mysql_error()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// TODO !!!!!! DEBUG -> error!!!! |
|
|
|
|
44
|
|
|
@$this->link = mysql_connect($settings['server'], $settings['user'], $settings['pass']); |
|
|
|
|
45
|
|
|
if (!is_resource($this->link)) { |
46
|
|
|
$debug->error_fatal('DB Error - cannot connect to server', $this->mysql_error()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->mysql_query("/*!40101 SET NAMES 'utf8' */") or $debug->error_fatal('DB error - cannot set names', $this->mysql_error()); |
|
|
|
|
50
|
|
|
$this->mysql_query("SET NAMES 'utf8';") or $debug->error_fatal('DB error - cannot set names', $this->mysql_error()); |
|
|
|
|
51
|
|
|
|
52
|
|
|
mysql_select_db($settings['name']) or $debug->error_fatal('DB error - cannot find DB on server', $this->mysql_error()); |
|
|
|
|
53
|
|
|
$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';') or $debug->error_fatal('DB error - cannot set desired isolation level', $this->mysql_error()); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->connected = true; |
56
|
|
|
|
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function mysql_query($query_string) { |
61
|
|
|
return mysql_query($query_string, $this->link); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function mysql_fetch_assoc(&$query) { |
65
|
|
|
return mysql_fetch_assoc($query); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function mysql_fetch_row(&$query) { |
69
|
|
|
return mysql_fetch_row($query); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function mysql_real_escape_string($unescaped_string) { |
73
|
|
|
return mysql_real_escape_string($unescaped_string, $this->link); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function mysql_close_link() { |
77
|
|
|
if ($this->connected) { |
78
|
|
|
$this->connected = false; |
79
|
|
|
mysql_close($this->link); |
|
|
|
|
80
|
|
|
unset($this->link); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return true; |
84
|
|
|
// return mysql_close($this->link); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function mysql_error() { |
88
|
|
|
return mysql_error($this->link); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function mysql_insert_id() { |
92
|
|
|
return mysql_insert_id($this->link); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function mysql_num_rows(&$result) { |
96
|
|
|
return mysql_num_rows($result); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function mysql_affected_rows() { |
100
|
|
|
return mysql_affected_rows($this->link); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function mysql_get_client_info() { |
104
|
|
|
return mysql_get_client_info(); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function mysql_get_server_info() { |
108
|
|
|
return mysql_get_server_info($this->link); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function mysql_get_host_info() { |
112
|
|
|
return mysql_get_host_info($this->link); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function mysql_stat() { |
116
|
|
|
return mysql_stat($this->link); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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.