@@ -33,15 +33,17 @@ discard block |
||
33 | 33 | { |
34 | 34 | $this->driverName = 'Mysqli'; |
35 | 35 | |
36 | - if (!array_key_exists("dbchar", $options)) |
|
37 | - $options["dbchar"] = "utf8"; |
|
36 | + if (!array_key_exists("dbchar", $options)) { |
|
37 | + $options["dbchar"] = "utf8"; |
|
38 | + } |
|
38 | 39 | |
39 | 40 | parent::__construct($options); |
40 | 41 | |
41 | 42 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
42 | 43 | |
43 | - if ($auto_connect) |
|
44 | - $this->connect(); |
|
44 | + if ($auto_connect) { |
|
45 | + $this->connect(); |
|
46 | + } |
|
45 | 47 | } |
46 | 48 | |
47 | 49 | /** |
@@ -54,13 +56,15 @@ discard block |
||
54 | 56 | */ |
55 | 57 | public function connect() |
56 | 58 | { |
57 | - if (!extension_loaded('mysqli')) |
|
58 | - throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
59 | + if (!extension_loaded('mysqli')) { |
|
60 | + throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
61 | + } |
|
59 | 62 | |
60 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
61 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
62 | - else |
|
63 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
63 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
64 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
65 | + } else { |
|
66 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
67 | + } |
|
64 | 68 | |
65 | 69 | if ($conn->connect_errno) |
66 | 70 | { |
@@ -71,8 +75,7 @@ discard block |
||
71 | 75 | */ |
72 | 76 | var_dump(mysqli_connect_errno()); |
73 | 77 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); |
74 | - } |
|
75 | - else |
|
78 | + } else |
|
76 | 79 | { |
77 | 80 | $this->dbconn = $conn; |
78 | 81 | $this->dbconn->set_charset($this->dbchar); |
@@ -119,13 +122,15 @@ discard block |
||
119 | 122 | |
120 | 123 | for ($i = 0; $i < $n_params; $i++) |
121 | 124 | { |
122 | - if (is_string($param_values[$i])) |
|
123 | - $bind_types .= 's'; |
|
124 | - else if(is_float($param_values[$i])) |
|
125 | - $bind_types .= 'd'; |
|
125 | + if (is_string($param_values[$i])) { |
|
126 | + $bind_types .= 's'; |
|
127 | + } else if(is_float($param_values[$i])) { |
|
128 | + $bind_types .= 'd'; |
|
129 | + } |
|
126 | 130 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
127 | - else |
|
128 | - $bind_types .= 's'; |
|
131 | + else { |
|
132 | + $bind_types .= 's'; |
|
133 | + } |
|
129 | 134 | |
130 | 135 | $bind_values[] = '$param_values[' . $i . ']'; |
131 | 136 | } |
@@ -134,8 +139,7 @@ discard block |
||
134 | 139 | eval('$stmt->bind_param(\'' . $bind_types . '\', ' . $values . ');'); |
135 | 140 | |
136 | 141 | $r = $stmt->execute(); |
137 | - } |
|
138 | - else |
|
142 | + } else |
|
139 | 143 | { |
140 | 144 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
141 | 145 | |
@@ -164,28 +168,33 @@ discard block |
||
164 | 168 | * It is useful to prevent rollback transactions on insert statements because |
165 | 169 | * insert statement do not free results. |
166 | 170 | */ |
167 | - if ($res) |
|
168 | - $this->result = $res; |
|
171 | + if ($res) { |
|
172 | + $this->result = $res; |
|
173 | + } |
|
169 | 174 | } |
170 | 175 | |
171 | 176 | # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries |
172 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) |
|
173 | - $this->numRows = $this->result->num_rows; |
|
174 | - else |
|
177 | + if (is_object($this->result) && property_exists($this->result, 'num_rows')) { |
|
178 | + $this->numRows = $this->result->num_rows; |
|
179 | + } else |
|
175 | 180 | { |
176 | - if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) |
|
177 | - $this->rowsAffected = $this->dbconn->affected_rows; |
|
181 | + if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) { |
|
182 | + $this->rowsAffected = $this->dbconn->affected_rows; |
|
183 | + } |
|
178 | 184 | } |
179 | 185 | |
180 | 186 | # affected_rows return the same of num_rows on select statements! |
181 | - if ($this->numRows > 0) |
|
182 | - $this->rowsAffected = 0; |
|
187 | + if ($this->numRows > 0) { |
|
188 | + $this->rowsAffected = 0; |
|
189 | + } |
|
183 | 190 | |
184 | - if (property_exists($this->dbconn, 'field_count')) |
|
185 | - $this->numFields = $this->dbconn->field_count; |
|
191 | + if (property_exists($this->dbconn, 'field_count')) { |
|
192 | + $this->numFields = $this->dbconn->field_count; |
|
193 | + } |
|
186 | 194 | |
187 | - if ($this->transac_mode) |
|
188 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
195 | + if ($this->transac_mode) { |
|
196 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
197 | + } |
|
189 | 198 | /* |
190 | 199 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, |
191 | 200 | * and TRUE for other successful queries, it should be handled to return only objects or resources. |
@@ -253,10 +262,10 @@ discard block |
||
253 | 262 | { |
254 | 263 | $data[] = $row; |
255 | 264 | } |
256 | - } |
|
257 | - else |
|
258 | - # This error is thrown because of 'execute' method has not been executed. |
|
265 | + } else { |
|
266 | + # This error is thrown because of 'execute' method has not been executed. |
|
259 | 267 | throw new \LogicException('There are not data in the buffer!'); |
268 | + } |
|
260 | 269 | |
261 | 270 | $this->arrayResult = $data; |
262 | 271 | |
@@ -271,7 +280,8 @@ discard block |
||
271 | 280 | public function __destruct() |
272 | 281 | { |
273 | 282 | # prevent "Property access is not allowed yet" with @ on failure connections |
274 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
275 | - @$this->dbconn->close(); |
|
283 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
284 | + @$this->dbconn->close(); |
|
285 | + } |
|
276 | 286 | } |
277 | 287 | } |
278 | 288 | \ No newline at end of file |