@@ -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 |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $this->numFields = $this->dbconn->field_count; |
| 179 | 179 | |
| 180 | 180 | if ($this->transac_mode) |
| 181 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 181 | + $this->transac_result = is_null($this->transac_result) ? $this->result : $this->transac_result && $this->result; |
|
| 182 | 182 | |
| 183 | 183 | /* |
| 184 | 184 | * 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 | |
@@ -165,20 +170,23 @@ discard block |
||
| 165 | 170 | } |
| 166 | 171 | |
| 167 | 172 | # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries |
| 168 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) |
|
| 169 | - $this->numRows = $this->result->num_rows; |
|
| 170 | - else |
|
| 173 | + if (is_object($this->result) && property_exists($this->result, 'num_rows')) { |
|
| 174 | + $this->numRows = $this->result->num_rows; |
|
| 175 | + } else |
|
| 171 | 176 | { |
| 172 | 177 | # affected_rows return the same of num_rows on select statements! |
| 173 | - if (property_exists($this->dbconn, 'affected_rows')) |
|
| 174 | - $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 178 | + if (property_exists($this->dbconn, 'affected_rows')) { |
|
| 179 | + $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 180 | + } |
|
| 175 | 181 | } |
| 176 | 182 | |
| 177 | - if (property_exists($this->dbconn, 'field_count')) |
|
| 178 | - $this->numFields = $this->dbconn->field_count; |
|
| 183 | + if (property_exists($this->dbconn, 'field_count')) { |
|
| 184 | + $this->numFields = $this->dbconn->field_count; |
|
| 185 | + } |
|
| 179 | 186 | |
| 180 | - if ($this->transac_mode) |
|
| 181 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 187 | + if ($this->transac_mode) { |
|
| 188 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 189 | + } |
|
| 182 | 190 | |
| 183 | 191 | /* |
| 184 | 192 | * 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. |
@@ -255,9 +263,8 @@ discard block |
||
| 255 | 263 | { |
| 256 | 264 | $data[] = $row; |
| 257 | 265 | } |
| 258 | - } |
|
| 259 | - else |
|
| 260 | - /* |
|
| 266 | + } else { |
|
| 267 | + /* |
|
| 261 | 268 | * "This kind of exception should lead directly to a fix in your code" |
| 262 | 269 | * So much production tests tell us this error is throwed because developers |
| 263 | 270 | * execute toArray() before execute(). |
@@ -265,6 +272,7 @@ discard block |
||
| 265 | 272 | * Ref: http://php.net/manual/en/class.logicexception.php |
| 266 | 273 | */ |
| 267 | 274 | throw new \LogicException('There are not data in the buffer!'); |
| 275 | + } |
|
| 268 | 276 | |
| 269 | 277 | $this->arrayResult = $data; |
| 270 | 278 | |
@@ -279,7 +287,8 @@ discard block |
||
| 279 | 287 | public function __destruct() |
| 280 | 288 | { |
| 281 | 289 | # prevent "Property access is not allowed yet" with @ on failure connections |
| 282 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
| 283 | - @$this->dbconn->close(); |
|
| 290 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
| 291 | + @$this->dbconn->close(); |
|
| 292 | + } |
|
| 284 | 293 | } |
| 285 | 294 | } |
| 286 | 295 | \ No newline at end of file |
@@ -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); |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | $result = $conn->execute($sql); |
| 268 | 268 | $rowcount = count($conn->getArrayResult()); |
| 269 | 269 | |
| 270 | - $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
| 270 | + $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
| 271 | 271 | |
| 272 | 272 | # properties modified by execute() method |
| 273 | 273 | $this->assertEquals(1, $conn->getNumRows()); |
| 274 | 274 | $this->assertEquals(2, $conn->getNumFields()); |
| 275 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 275 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 276 | 276 | |
| 277 | 277 | $this->assertTrue($conn->commit()); |
| 278 | 278 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | $result = $conn->execute($sql); |
| 282 | 282 | $rowcount = count($conn->getArrayResult()); |
| 283 | 283 | |
| 284 | - $this->assertTrue(($rowcount === 1)); # the row is available |
|
| 284 | + $this->assertTrue(($rowcount === 1)); # the row is available |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -304,12 +304,12 @@ discard block |
||
| 304 | 304 | $result = $conn->execute($sql); |
| 305 | 305 | $rowcount = count($conn->getArrayResult()); |
| 306 | 306 | |
| 307 | - $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
| 307 | + $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
| 308 | 308 | |
| 309 | 309 | # properties modified by execute() method |
| 310 | 310 | $this->assertEquals(1, $conn->getNumRows()); |
| 311 | 311 | $this->assertEquals(2, $conn->getNumFields()); |
| 312 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 312 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 313 | 313 | |
| 314 | 314 | $this->assertTrue($conn->rollback()); |
| 315 | 315 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | $result = $conn->execute($sql); |
| 319 | 319 | $rowcount = count($conn->getArrayResult()); |
| 320 | 320 | |
| 321 | - $this->assertNotTrue(($rowcount === 1)); # the row is not available |
|
| 321 | + $this->assertNotTrue(($rowcount === 1)); # the row is not available |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -350,12 +350,12 @@ discard block |
||
| 350 | 350 | $result = $conn->execute($sql); |
| 351 | 351 | $rowcount = count($conn->getArrayResult()); |
| 352 | 352 | |
| 353 | - $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
| 353 | + $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
| 354 | 354 | |
| 355 | 355 | # properties modified by execute() method |
| 356 | 356 | $this->assertEquals(4, $conn->getNumRows()); |
| 357 | 357 | $this->assertEquals(2, $conn->getNumFields()); |
| 358 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 358 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 359 | 359 | |
| 360 | 360 | $this->assertTrue($conn->commit()); |
| 361 | 361 | |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $result = $conn->execute($sql); |
| 365 | 365 | $rowcount = count($conn->getArrayResult()); |
| 366 | 366 | |
| 367 | - $this->assertTrue(($rowcount === 4)); # the row is available |
|
| 367 | + $this->assertTrue(($rowcount === 4)); # the row is available |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -396,12 +396,12 @@ discard block |
||
| 396 | 396 | $result = $conn->execute($sql); |
| 397 | 397 | $rowcount = count($conn->getArrayResult()); |
| 398 | 398 | |
| 399 | - $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
| 399 | + $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
| 400 | 400 | |
| 401 | 401 | # properties modified by execute() method |
| 402 | 402 | $this->assertEquals(4, $conn->getNumRows()); |
| 403 | 403 | $this->assertEquals(2, $conn->getNumFields()); |
| 404 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 404 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 405 | 405 | |
| 406 | 406 | $this->assertTrue($conn->rollback()); |
| 407 | 407 | |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | $result = $conn->execute($sql); |
| 411 | 411 | $rowcount = count($conn->getArrayResult()); |
| 412 | 412 | |
| 413 | - $this->assertNotTrue(($rowcount === 4)); # the row is available |
|
| 413 | + $this->assertNotTrue(($rowcount === 4)); # the row is available |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -441,12 +441,12 @@ discard block |
||
| 441 | 441 | $result = $conn->execute($sql); |
| 442 | 442 | $rowcount = count($conn->getArrayResult()); |
| 443 | 443 | |
| 444 | - $this->assertTrue(($rowcount === 2)); # the rows are available for now |
|
| 444 | + $this->assertTrue(($rowcount === 2)); # the rows are available for now |
|
| 445 | 445 | |
| 446 | 446 | # properties modified by execute() method |
| 447 | 447 | $this->assertEquals(2, $conn->getNumRows()); |
| 448 | 448 | $this->assertEquals(2, $conn->getNumFields()); |
| 449 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 449 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
| 450 | 450 | |
| 451 | 451 | # ends the transaction |
| 452 | 452 | $conn->endTransaction(); |
@@ -456,6 +456,6 @@ discard block |
||
| 456 | 456 | $result = $conn->execute($sql); |
| 457 | 457 | $rowcount = count($conn->getArrayResult()); |
| 458 | 458 | |
| 459 | - $this->assertTrue(($rowcount === 2)); # the row is available |
|
| 459 | + $this->assertTrue(($rowcount === 2)); # the row is available |
|
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | \ No newline at end of file |