@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | if (is_string($param_values[$i])) |
| 120 | 120 | $bind_types .= 's'; |
| 121 | - else if(is_float($param_values[$i])) |
|
| 121 | + else if (is_float($param_values[$i])) |
|
| 122 | 122 | $bind_types .= 'd'; |
| 123 | 123 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 124 | 124 | else |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $this->rowsAffected = $this->dbconn->affected_rows; |
| 175 | 175 | |
| 176 | 176 | if ($this->transac_mode) |
| 177 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 177 | + $this->transac_result = is_null($this->transac_result) ? $this->result : $this->transac_result && $this->result; |
|
| 178 | 178 | |
| 179 | 179 | /* |
| 180 | 180 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, * and TRUE for other successful queries, it should be handled to return only objects or resources. |
@@ -31,15 +31,17 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function __construct($options) |
| 33 | 33 | { |
| 34 | - if (!array_key_exists("dbchar", $options)) |
|
| 35 | - $options["dbchar"] = "utf8"; |
|
| 34 | + if (!array_key_exists("dbchar", $options)) { |
|
| 35 | + $options["dbchar"] = "utf8"; |
|
| 36 | + } |
|
| 36 | 37 | |
| 37 | 38 | parent::__construct($options); |
| 38 | 39 | |
| 39 | 40 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
| 40 | 41 | |
| 41 | - if ($auto_connect) |
|
| 42 | - $this->connect(); |
|
| 42 | + if ($auto_connect) { |
|
| 43 | + $this->connect(); |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | /** |
@@ -52,13 +54,15 @@ discard block |
||
| 52 | 54 | */ |
| 53 | 55 | public function connect() |
| 54 | 56 | { |
| 55 | - if (!extension_loaded('mysqli')) |
|
| 56 | - throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 57 | + if (!extension_loaded('mysqli')) { |
|
| 58 | + throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 59 | + } |
|
| 57 | 60 | |
| 58 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
| 59 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 60 | - else |
|
| 61 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 61 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
| 62 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 63 | + } else { |
|
| 64 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 65 | + } |
|
| 62 | 66 | |
| 63 | 67 | if ($conn->connect_errno) |
| 64 | 68 | { |
@@ -68,8 +72,7 @@ discard block |
||
| 68 | 72 | * the warning message "Property access is not allowed yet". |
| 69 | 73 | */ |
| 70 | 74 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); |
| 71 | - } |
|
| 72 | - else |
|
| 75 | + } else |
|
| 73 | 76 | { |
| 74 | 77 | $this->dbconn = $conn; |
| 75 | 78 | $this->dbconn->set_charset($this->dbchar); |
@@ -116,13 +119,15 @@ discard block |
||
| 116 | 119 | |
| 117 | 120 | for ($i = 0; $i < $n_params; $i++) |
| 118 | 121 | { |
| 119 | - if (is_string($param_values[$i])) |
|
| 120 | - $bind_types .= 's'; |
|
| 121 | - else if(is_float($param_values[$i])) |
|
| 122 | - $bind_types .= 'd'; |
|
| 122 | + if (is_string($param_values[$i])) { |
|
| 123 | + $bind_types .= 's'; |
|
| 124 | + } else if(is_float($param_values[$i])) { |
|
| 125 | + $bind_types .= 'd'; |
|
| 126 | + } |
|
| 123 | 127 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 124 | - else |
|
| 125 | - $bind_types .= 's'; |
|
| 128 | + else { |
|
| 129 | + $bind_types .= 's'; |
|
| 130 | + } |
|
| 126 | 131 | |
| 127 | 132 | $bind_values[] = '$param_values[' . $i . ']'; |
| 128 | 133 | } |
@@ -143,12 +148,12 @@ discard block |
||
| 143 | 148 | * It is useful to prevent rollback transactions on insert statements because |
| 144 | 149 | * insert statement do not free results. |
| 145 | 150 | */ |
| 146 | - if ($res) |
|
| 147 | - $this->result = $res; |
|
| 151 | + if ($res) { |
|
| 152 | + $this->result = $res; |
|
| 153 | + } |
|
| 148 | 154 | } |
| 149 | 155 | } |
| 150 | - } |
|
| 151 | - else |
|
| 156 | + } else |
|
| 152 | 157 | { |
| 153 | 158 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
| 154 | 159 | |
@@ -164,17 +169,21 @@ discard block |
||
| 164 | 169 | throw new Exception\InvalidQueryException($this->dbconn->error, $this->dbconn->errno); |
| 165 | 170 | } |
| 166 | 171 | |
| 167 | - if (property_exists($this->dbconn, 'num_rows')) |
|
| 168 | - $this->numRows = $this->dbconn->num_rows; |
|
| 172 | + if (property_exists($this->dbconn, 'num_rows')) { |
|
| 173 | + $this->numRows = $this->dbconn->num_rows; |
|
| 174 | + } |
|
| 169 | 175 | |
| 170 | - if (property_exists($this->dbconn, 'field_count')) |
|
| 171 | - $this->numFields = $this->dbconn->field_count; |
|
| 176 | + if (property_exists($this->dbconn, 'field_count')) { |
|
| 177 | + $this->numFields = $this->dbconn->field_count; |
|
| 178 | + } |
|
| 172 | 179 | |
| 173 | - if (property_exists($this->dbconn, 'affected_rows')) |
|
| 174 | - $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 180 | + if (property_exists($this->dbconn, 'affected_rows')) { |
|
| 181 | + $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 182 | + } |
|
| 175 | 183 | |
| 176 | - if ($this->transac_mode) |
|
| 177 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 184 | + if ($this->transac_mode) { |
|
| 185 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 186 | + } |
|
| 178 | 187 | |
| 179 | 188 | /* |
| 180 | 189 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, * and TRUE for other successful queries, it should be handled to return only objects or resources. |
@@ -251,9 +260,8 @@ discard block |
||
| 251 | 260 | { |
| 252 | 261 | $data[] = $row; |
| 253 | 262 | } |
| 254 | - } |
|
| 255 | - else |
|
| 256 | - /* |
|
| 263 | + } else { |
|
| 264 | + /* |
|
| 257 | 265 | * "This kind of exception should lead directly to a fix in your code" |
| 258 | 266 | * So much production tests tell us this error is throwed because developers |
| 259 | 267 | * execute toArray() before execute(). |
@@ -261,6 +269,7 @@ discard block |
||
| 261 | 269 | * Ref: http://php.net/manual/en/class.logicexception.php |
| 262 | 270 | */ |
| 263 | 271 | throw new \LogicException('There are not data in the buffer!'); |
| 272 | + } |
|
| 264 | 273 | |
| 265 | 274 | $this->arrayResult = $data; |
| 266 | 275 | |
@@ -275,7 +284,8 @@ discard block |
||
| 275 | 284 | public function __destruct() |
| 276 | 285 | { |
| 277 | 286 | # prevent "Property access is not allowed yet" with @ on failure connections |
| 278 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
| 279 | - @$this->dbconn->close(); |
|
| 287 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
| 288 | + @$this->dbconn->close(); |
|
| 289 | + } |
|
| 280 | 290 | } |
| 281 | 291 | } |
| 282 | 292 | \ No newline at end of file |
@@ -216,8 +216,9 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function getArrayResult() |
| 218 | 218 | { |
| 219 | - if (!empty($this->arrayResult)) |
|
| 220 | - return $this->arrayResult; |
|
| 219 | + if (!empty($this->arrayResult)) { |
|
| 220 | + return $this->arrayResult; |
|
| 221 | + } |
|
| 221 | 222 | |
| 222 | 223 | return $this->toArray(); |
| 223 | 224 | } |
@@ -313,8 +314,9 @@ discard block |
||
| 313 | 314 | */ |
| 314 | 315 | public function autocommit($value) |
| 315 | 316 | { |
| 316 | - if ($this->transac_mode) |
|
| 317 | - throw new \LogicException("You cannot change autocommit behavior during a transaction"); |
|
| 317 | + if ($this->transac_mode) { |
|
| 318 | + throw new \LogicException("You cannot change autocommit behavior during a transaction"); |
|
| 319 | + } |
|
| 318 | 320 | |
| 319 | 321 | $this->autocommit = $value; |
| 320 | 322 | } |
@@ -330,8 +332,9 @@ discard block |
||
| 330 | 332 | { |
| 331 | 333 | foreach ($options as $option => $value) |
| 332 | 334 | { |
| 333 | - if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) |
|
| 334 | - $this->{'set'.$option}($value); |
|
| 335 | + if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) { |
|
| 336 | + $this->{'set'.$option}($value); |
|
| 337 | + } |
|
| 335 | 338 | } |
| 336 | 339 | } |
| 337 | 340 | |
@@ -375,8 +378,9 @@ discard block |
||
| 375 | 378 | */ |
| 376 | 379 | public function reconnect() |
| 377 | 380 | { |
| 378 | - if (!$this->isConnected()) |
|
| 379 | - throw new \LogicException("Connection was not established"); |
|
| 381 | + if (!$this->isConnected()) { |
|
| 382 | + throw new \LogicException("Connection was not established"); |
|
| 383 | + } |
|
| 380 | 384 | |
| 381 | 385 | $this->disconnect(); |
| 382 | 386 | return $this->connect(); |
@@ -405,8 +409,9 @@ discard block |
||
| 405 | 409 | */ |
| 406 | 410 | public function disconnect() |
| 407 | 411 | { |
| 408 | - if (!$this->isConnected()) |
|
| 409 | - throw new \LogicException("Connection was not established"); |
|
| 412 | + if (!$this->isConnected()) { |
|
| 413 | + throw new \LogicException("Connection was not established"); |
|
| 414 | + } |
|
| 410 | 415 | } |
| 411 | 416 | |
| 412 | 417 | /** |
@@ -418,11 +423,13 @@ discard block |
||
| 418 | 423 | */ |
| 419 | 424 | public function beginTransaction() |
| 420 | 425 | { |
| 421 | - if (!$this->isConnected()) |
|
| 422 | - $this->connect(); |
|
| 426 | + if (!$this->isConnected()) { |
|
| 427 | + $this->connect(); |
|
| 428 | + } |
|
| 423 | 429 | |
| 424 | - if ($this->transac_mode) |
|
| 425 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]); |
|
| 430 | + if ($this->transac_mode) { |
|
| 431 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]); |
|
| 432 | + } |
|
| 426 | 433 | |
| 427 | 434 | $this->transac_mode = true; |
| 428 | 435 | } |
@@ -436,16 +443,19 @@ discard block |
||
| 436 | 443 | */ |
| 437 | 444 | public function endTransaction() |
| 438 | 445 | { |
| 439 | - if (!$this->transac_mode) |
|
| 440 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]); |
|
| 446 | + if (!$this->transac_mode) { |
|
| 447 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]); |
|
| 448 | + } |
|
| 441 | 449 | |
| 442 | - if (is_null($this->transac_result)) |
|
| 443 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]); |
|
| 450 | + if (is_null($this->transac_result)) { |
|
| 451 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]); |
|
| 452 | + } |
|
| 444 | 453 | |
| 445 | - if ($this->transac_result) |
|
| 446 | - $this->commit(); |
|
| 447 | - else |
|
| 448 | - $this->rollback(); |
|
| 454 | + if ($this->transac_result) { |
|
| 455 | + $this->commit(); |
|
| 456 | + } else { |
|
| 457 | + $this->rollback(); |
|
| 458 | + } |
|
| 449 | 459 | |
| 450 | 460 | $this->result = $this->transac_result; |
| 451 | 461 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | public function testCannotStablishConnection() |
| 145 | 145 | { |
| 146 | 146 | $options = $this->options; |
| 147 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
| 147 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
| 148 | 148 | |
| 149 | 149 | $conn = new MySQL($options); |
| 150 | 150 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $this->assertEquals(2, $conn->getNumFields()); |
| 241 | 241 | $this->assertEquals(0, $conn->getRowsAffected()); |
| 242 | 242 | |
| 243 | - $rowset = $conn->getArrayResult(); # array with results |
|
| 243 | + $rowset = $conn->getArrayResult(); # array with results |
|
| 244 | 244 | $row = array_shift($rowset); |
| 245 | 245 | |
| 246 | 246 | $this->assertArrayHasKey("ID", $row); |
@@ -83,12 +83,10 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | try { |
| 85 | 85 | $conn->disconnect(); |
| 86 | - } |
|
| 87 | - catch (\Exception $e) |
|
| 86 | + } catch (\Exception $e) |
|
| 88 | 87 | { |
| 89 | 88 | $errorObject = ($e instanceof \LogicException); |
| 90 | - } |
|
| 91 | - finally |
|
| 89 | + } finally |
|
| 92 | 90 | { |
| 93 | 91 | $this->assertNotTrue($conn->isConnected()); |
| 94 | 92 | $this->assertTrue($errorObject, $e->getMessage()); |
@@ -124,12 +122,10 @@ discard block |
||
| 124 | 122 | |
| 125 | 123 | try { |
| 126 | 124 | $conn->reconnect(); |
| 127 | - } |
|
| 128 | - catch (\Exception $e) |
|
| 125 | + } catch (\Exception $e) |
|
| 129 | 126 | { |
| 130 | 127 | $errorObject = ($e instanceof \LogicException); |
| 131 | - } |
|
| 132 | - finally |
|
| 128 | + } finally |
|
| 133 | 129 | { |
| 134 | 130 | $this->assertTrue($errorObject, $e->getMessage()); |
| 135 | 131 | $this->assertNotTrue($conn->isConnected()); |
@@ -154,13 +150,11 @@ discard block |
||
| 154 | 150 | |
| 155 | 151 | try { |
| 156 | 152 | $mysqliObject = $conn->connect(); |
| 157 | - } |
|
| 158 | - catch (\Exception $e) |
|
| 153 | + } catch (\Exception $e) |
|
| 159 | 154 | { |
| 160 | 155 | $errorObject = ($e instanceof ConnectionException); |
| 161 | 156 | $message = $e->getMessage(); |
| 162 | - } |
|
| 163 | - finally |
|
| 157 | + } finally |
|
| 164 | 158 | { |
| 165 | 159 | $this->assertTrue($errorObject, $message); |
| 166 | 160 | $this->assertNotTrue($conn->isConnected()); |