@@ -53,8 +53,11 @@ discard block |
||
53 | 53 | $globalDBSname = $globalDBname; |
54 | 54 | $globalDBSuser = $globalDBuser; |
55 | 55 | $globalDBSpass = $globalDBpass; |
56 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') $globalDBSport = 3306; |
|
57 | - else $globalDBSport = intval($globalDBport); |
|
56 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') { |
|
57 | + $globalDBSport = 3306; |
|
58 | + } else { |
|
59 | + $globalDBSport = intval($globalDBport); |
|
60 | + } |
|
58 | 61 | } else { |
59 | 62 | $DBname = 'default'; |
60 | 63 | $globalDBSdriver = $globalDBdriver; |
@@ -62,8 +65,11 @@ discard block |
||
62 | 65 | $globalDBSname = $globalDBname; |
63 | 66 | $globalDBSuser = $user; |
64 | 67 | $globalDBSpass = $pass; |
65 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') $globalDBSport = 3306; |
|
66 | - else $globalDBSport = intval($globalDBport); |
|
68 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') { |
|
69 | + $globalDBSport = 3306; |
|
70 | + } else { |
|
71 | + $globalDBSport = intval($globalDBport); |
|
72 | + } |
|
67 | 73 | } |
68 | 74 | } else { |
69 | 75 | $globalDBSdriver = $globalDB[$DBname]['driver']; |
@@ -71,11 +77,16 @@ discard block |
||
71 | 77 | $globalDBSname = $globalDB[$DBname]['name']; |
72 | 78 | $globalDBSuser = $globalDB[$DBname]['user']; |
73 | 79 | $globalDBSpass = $globalDB[$DBname]['pass']; |
74 | - if (isset($globalDB[$DBname]['port'])) $globalDBSport = intval($globalDB[$DBname]['port']); |
|
75 | - else $globalDBSport = 3306; |
|
80 | + if (isset($globalDB[$DBname]['port'])) { |
|
81 | + $globalDBSport = intval($globalDB[$DBname]['port']); |
|
82 | + } else { |
|
83 | + $globalDBSport = 3306; |
|
84 | + } |
|
76 | 85 | } |
77 | 86 | // Set number of try to connect to DB |
78 | - if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 5; |
|
87 | + if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) { |
|
88 | + $globalDBretry = 5; |
|
89 | + } |
|
79 | 90 | $i = 0; |
80 | 91 | while (true) { |
81 | 92 | try { |
@@ -84,10 +95,16 @@ discard block |
||
84 | 95 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
85 | 96 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
86 | 97 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
87 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
88 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
89 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
90 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
98 | + if (!isset($globalDBTimeOut)) { |
|
99 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
100 | + } else { |
|
101 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
102 | + } |
|
103 | + if (!isset($globalDBPersistent)) { |
|
104 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
105 | + } else { |
|
106 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
107 | + } |
|
91 | 108 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
92 | 109 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
93 | 110 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
@@ -98,22 +115,34 @@ discard block |
||
98 | 115 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
99 | 116 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
100 | 117 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
101 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
102 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
103 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
104 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
118 | + if (!isset($globalDBTimeOut)) { |
|
119 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
120 | + } else { |
|
121 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
122 | + } |
|
123 | + if (!isset($globalDBPersistent)) { |
|
124 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
125 | + } else { |
|
126 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
127 | + } |
|
105 | 128 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
106 | 129 | } |
107 | 130 | break; |
108 | 131 | } catch(PDOException $e) { |
109 | 132 | $i++; |
110 | - if (isset($globalDebug) && $globalDebug) echo $e->getMessage()."\n"; |
|
133 | + if (isset($globalDebug) && $globalDebug) { |
|
134 | + echo $e->getMessage()."\n"; |
|
135 | + } |
|
111 | 136 | //exit; |
112 | - if ($i > $globalDBretry) return false; |
|
137 | + if ($i > $globalDBretry) { |
|
138 | + return false; |
|
139 | + } |
|
113 | 140 | //return false; |
114 | 141 | } |
115 | 142 | } |
116 | - if ($DBname === 'default') $this->db = $this->dbs['default']; |
|
143 | + if ($DBname === 'default') { |
|
144 | + $this->db = $this->dbs['default']; |
|
145 | + } |
|
117 | 146 | return true; |
118 | 147 | } |
119 | 148 | |
@@ -125,7 +154,9 @@ discard block |
||
125 | 154 | } elseif ($globalDBdriver == 'pgsql') { |
126 | 155 | $query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'"; |
127 | 156 | } |
128 | - if ($this->db == NULL) return false; |
|
157 | + if ($this->db == NULL) { |
|
158 | + return false; |
|
159 | + } |
|
129 | 160 | try { |
130 | 161 | //$Connection = new Connection(); |
131 | 162 | $results = $this->db->query($query); |
@@ -134,21 +165,28 @@ discard block |
||
134 | 165 | } |
135 | 166 | if($results->rowCount()>0) { |
136 | 167 | return true; |
168 | + } else { |
|
169 | + return false; |
|
137 | 170 | } |
138 | - else return false; |
|
139 | 171 | } |
140 | 172 | |
141 | 173 | public function connectionExists() |
142 | 174 | { |
143 | 175 | global $globalDBdriver, $globalDBCheckConnection; |
144 | - if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true; |
|
176 | + if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) { |
|
177 | + return true; |
|
178 | + } |
|
145 | 179 | $query = "SELECT 1 + 1"; |
146 | - if ($this->db == NULL) return false; |
|
180 | + if ($this->db == NULL) { |
|
181 | + return false; |
|
182 | + } |
|
147 | 183 | try { |
148 | 184 | $sum = @$this->db->query($query); |
149 | 185 | if ($sum instanceof \PDOStatement) { |
150 | 186 | $sum = $sum->fetchColumn(0); |
151 | - } else $sum = 0; |
|
187 | + } else { |
|
188 | + $sum = 0; |
|
189 | + } |
|
152 | 190 | if (intval($sum) !== 2) { |
153 | 191 | return false; |
154 | 192 | } |
@@ -182,8 +220,9 @@ discard block |
||
182 | 220 | } |
183 | 221 | if($results->rowCount()>0) { |
184 | 222 | return true; |
223 | + } else { |
|
224 | + return false; |
|
185 | 225 | } |
186 | - else return false; |
|
187 | 226 | } |
188 | 227 | |
189 | 228 | /* |
@@ -222,7 +261,9 @@ discard block |
||
222 | 261 | $colcnt = $results->columnCount(); |
223 | 262 | for ($i = 0; $i < $colcnt; $i++) { |
224 | 263 | $col = $results->getColumnMeta($i); |
225 | - if ($name == $col['name']) return true; |
|
264 | + if ($name == $col['name']) { |
|
265 | + return true; |
|
266 | + } |
|
226 | 267 | } |
227 | 268 | return false; |
228 | 269 | } |
@@ -249,7 +290,9 @@ discard block |
||
249 | 290 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
250 | 291 | return $result['value']; |
251 | 292 | } |
252 | - } else return $version; |
|
293 | + } else { |
|
294 | + return $version; |
|
295 | + } |
|
253 | 296 | } |
254 | 297 | |
255 | 298 | /* |
@@ -257,8 +300,11 @@ discard block |
||
257 | 300 | * @return Boolean if latest version or not |
258 | 301 | */ |
259 | 302 | public function latest() { |
260 | - if ($this->check_schema_version() == $this->latest_schema) return true; |
|
261 | - else return false; |
|
303 | + if ($this->check_schema_version() == $this->latest_schema) { |
|
304 | + return true; |
|
305 | + } else { |
|
306 | + return false; |
|
307 | + } |
|
262 | 308 | } |
263 | 309 | |
264 | 310 | } |