@@ -441,7 +441,7 @@ |
||
441 | 441 | parent::__construct($data); |
442 | 442 | $this->setTableName("MYTABLE"); |
443 | 443 | //$this->setConnectionParams("local"); |
444 | - } |
|
444 | + } |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | class MyEntityGateway extends TableGateway |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function testCannotStablishConnectionWhenExists() |
69 | 69 | { |
70 | 70 | $options = $this->options; |
71 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
71 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
72 | 72 | |
73 | 73 | $errorObject = null; |
74 | 74 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | public function testCannotStablishConnection() |
99 | 99 | { |
100 | 100 | $options = $this->options; |
101 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
101 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
102 | 102 | |
103 | 103 | $entity = new MyEntity(); |
104 | 104 | $gateway = new TableGateway($entity, ["other" => $options]); |
@@ -78,13 +78,11 @@ discard block |
||
78 | 78 | { |
79 | 79 | $entity = new MyEntity(); |
80 | 80 | $gateway = new TableGateway($entity, ["default" => $options]); |
81 | - } |
|
82 | - catch (\Exception $e) |
|
81 | + } catch (\Exception $e) |
|
83 | 82 | { |
84 | 83 | $errorObject = ($e instanceof \RuntimeException); |
85 | 84 | $message = $e->getMessage(); |
86 | - } |
|
87 | - finally |
|
85 | + } finally |
|
88 | 86 | { |
89 | 87 | $this->assertTrue($errorObject, $message); |
90 | 88 | } |
@@ -110,13 +108,11 @@ discard block |
||
110 | 108 | try |
111 | 109 | { |
112 | 110 | $gateway->getDb()->connect(); |
113 | - } |
|
114 | - catch (\Exception $e) |
|
111 | + } catch (\Exception $e) |
|
115 | 112 | { |
116 | 113 | $errorObject = ($e instanceof ConnectionException); |
117 | 114 | $message = $e->getMessage(); |
118 | - } |
|
119 | - finally |
|
115 | + } finally |
|
120 | 116 | { |
121 | 117 | $this->assertTrue($errorObject, $message); |
122 | 118 | $this->assertNotTrue($gateway->getDb()->isConnected()); |
@@ -145,13 +141,11 @@ discard block |
||
145 | 141 | try |
146 | 142 | { |
147 | 143 | AbstractTableGateway::getDriver('other3'); |
148 | - } |
|
149 | - catch (\Exception $e) |
|
144 | + } catch (\Exception $e) |
|
150 | 145 | { |
151 | 146 | $errorObject = ($e instanceof \RuntimeException); |
152 | 147 | $message = $e->getMessage(); |
153 | - } |
|
154 | - finally |
|
148 | + } finally |
|
155 | 149 | { |
156 | 150 | $this->assertTrue($errorObject, $message); |
157 | 151 | } |
@@ -250,13 +244,11 @@ discard block |
||
250 | 244 | try |
251 | 245 | { |
252 | 246 | $gateway->wrongDML(); |
253 | - } |
|
254 | - catch (\Exception $e) |
|
247 | + } catch (\Exception $e) |
|
255 | 248 | { |
256 | 249 | $errorObject = ($e instanceof InvalidQueryException); |
257 | 250 | $message = $e->getMessage(); |
258 | - } |
|
259 | - finally |
|
251 | + } finally |
|
260 | 252 | { |
261 | 253 | $this->assertTrue($errorObject, $message); |
262 | 254 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | public function testCannotStablishConnection() |
146 | 146 | { |
147 | 147 | $options = $this->options; |
148 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
148 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
149 | 149 | |
150 | 150 | $conn = new MySQL($options); |
151 | 151 | |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | $this->assertEquals(2, $conn->getNumFields()); |
275 | 275 | $this->assertEquals(0, $conn->getRowsAffected()); |
276 | 276 | |
277 | - $rowset = $conn->getArrayResult(); # array with results |
|
277 | + $rowset = $conn->getArrayResult(); # array with results |
|
278 | 278 | $row = array_shift($rowset); |
279 | 279 | |
280 | 280 | $this->assertArrayHasKey("ID", $row); |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | $conn->execute($sql); |
302 | 302 | $rowcount = count($conn->getArrayResult()); |
303 | 303 | |
304 | - $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
304 | + $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
305 | 305 | |
306 | 306 | # properties modified by execute() method |
307 | 307 | $this->assertEquals(1, $conn->getNumRows()); |
308 | 308 | $this->assertEquals(2, $conn->getNumFields()); |
309 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
309 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
310 | 310 | |
311 | 311 | $this->assertTrue($conn->commit()); |
312 | 312 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | $conn->execute($sql); |
316 | 316 | $rowcount = count($conn->getArrayResult()); |
317 | 317 | |
318 | - $this->assertTrue(($rowcount === 1)); # the row is available |
|
318 | + $this->assertTrue(($rowcount === 1)); # the row is available |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | $conn->execute($sql); |
339 | 339 | $rowcount = count($conn->getArrayResult()); |
340 | 340 | |
341 | - $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
341 | + $this->assertTrue(($rowcount === 1)); # the row is available for now |
|
342 | 342 | |
343 | 343 | # properties modified by execute() method |
344 | 344 | $this->assertEquals(1, $conn->getNumRows()); |
345 | 345 | $this->assertEquals(2, $conn->getNumFields()); |
346 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
346 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
347 | 347 | |
348 | 348 | $this->assertTrue($conn->rollback()); |
349 | 349 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $conn->execute($sql); |
353 | 353 | $rowcount = count($conn->getArrayResult()); |
354 | 354 | |
355 | - $this->assertNotTrue(($rowcount === 1)); # the row is not available |
|
355 | + $this->assertNotTrue(($rowcount === 1)); # the row is not available |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -384,12 +384,12 @@ discard block |
||
384 | 384 | $conn->execute($sql); |
385 | 385 | $rowcount = count($conn->getArrayResult()); |
386 | 386 | |
387 | - $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
387 | + $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
388 | 388 | |
389 | 389 | # properties modified by execute() method |
390 | 390 | $this->assertEquals(4, $conn->getNumRows()); |
391 | 391 | $this->assertEquals(2, $conn->getNumFields()); |
392 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
392 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
393 | 393 | |
394 | 394 | $this->assertTrue($conn->commit()); |
395 | 395 | |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | $conn->execute($sql); |
399 | 399 | $rowcount = count($conn->getArrayResult()); |
400 | 400 | |
401 | - $this->assertTrue(($rowcount === 4)); # the rows are available |
|
401 | + $this->assertTrue(($rowcount === 4)); # the rows are available |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -430,12 +430,12 @@ discard block |
||
430 | 430 | $conn->execute($sql); |
431 | 431 | $rowcount = count($conn->getArrayResult()); |
432 | 432 | |
433 | - $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
433 | + $this->assertTrue(($rowcount === 4)); # the rows are available for now |
|
434 | 434 | |
435 | 435 | # properties modified by execute() method |
436 | 436 | $this->assertEquals(4, $conn->getNumRows()); |
437 | 437 | $this->assertEquals(2, $conn->getNumFields()); |
438 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
438 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
439 | 439 | |
440 | 440 | $this->assertTrue($conn->rollback()); |
441 | 441 | |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $conn->execute($sql); |
445 | 445 | $rowcount = count($conn->getArrayResult()); |
446 | 446 | |
447 | - $this->assertNotTrue(($rowcount === 4)); # the rows are not available |
|
447 | + $this->assertNotTrue(($rowcount === 4)); # the rows are not available |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | $conn->execute($sql); |
476 | 476 | $rowcount = count($conn->getArrayResult()); |
477 | 477 | |
478 | - $this->assertTrue(($rowcount === 2)); # the rows are available for now |
|
478 | + $this->assertTrue(($rowcount === 2)); # the rows are available for now |
|
479 | 479 | |
480 | 480 | # properties modified by execute() method |
481 | 481 | $this->assertEquals(2, $conn->getNumRows()); |
482 | 482 | $this->assertEquals(2, $conn->getNumFields()); |
483 | - $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
483 | + $this->assertEquals(0, $conn->getRowsAffected()); # nothing affected (autocommit = false) |
|
484 | 484 | |
485 | 485 | # ends the transaction |
486 | 486 | $conn->endTransaction(); |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | $conn->execute($sql); |
491 | 491 | $rowcount = count($conn->getArrayResult()); |
492 | 492 | |
493 | - $this->assertTrue(($rowcount === 2)); # the row is available |
|
493 | + $this->assertTrue(($rowcount === 2)); # the row is available |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | $conn->execute($sql); |
535 | 535 | $rowcount = count($conn->getArrayResult()); |
536 | 536 | |
537 | - $this->assertNotTrue(($rowcount === 0)); # the rows are not available |
|
537 | + $this->assertNotTrue(($rowcount === 0)); # the rows are not available |
|
538 | 538 | |
539 | 539 | # remove all work |
540 | 540 | $conn->execute("DROP TABLE MYTABLE"); |
@@ -87,24 +87,25 @@ discard block |
||
87 | 87 | { |
88 | 88 | $this->currentConnection = $connection; |
89 | 89 | $this->getDriver($connection); |
90 | - } |
|
91 | - else if (is_array($connection)) |
|
90 | + } else if (is_array($connection)) |
|
92 | 91 | { |
93 | 92 | $identifier = key($connection); |
94 | 93 | $connection_options = $connection[$identifier]; |
95 | 94 | |
96 | 95 | $this->currentConnection = $identifier; |
97 | 96 | |
98 | - if (!array_key_exists('driver', $connection_options)) |
|
99 | - throw new \RuntimeException("The database driver key has not been declared"); |
|
100 | - |
|
101 | - if (!isset(self::$drivers[$identifier])) |
|
102 | - self::$drivers[$identifier] = DriverFactory::create($connection_options); |
|
103 | - else |
|
104 | - throw new \RuntimeException("The database connection already exists"); |
|
97 | + if (!array_key_exists('driver', $connection_options)) { |
|
98 | + throw new \RuntimeException("The database driver key has not been declared"); |
|
99 | + } |
|
100 | + |
|
101 | + if (!isset(self::$drivers[$identifier])) { |
|
102 | + self::$drivers[$identifier] = DriverFactory::create($connection_options); |
|
103 | + } else { |
|
104 | + throw new \RuntimeException("The database connection already exists"); |
|
105 | + } |
|
106 | + } else { |
|
107 | + throw new \InvalidArgumentException("Invalid type given. Array or string expected"); |
|
105 | 108 | } |
106 | - else |
|
107 | - throw new \InvalidArgumentException("Invalid type given. Array or string expected"); |
|
108 | 109 | } |
109 | 110 | |
110 | 111 | /** |
@@ -118,8 +119,9 @@ discard block |
||
118 | 119 | */ |
119 | 120 | public static function getDriver($identifier) |
120 | 121 | { |
121 | - if (!array_key_exists($identifier, self::$drivers)) |
|
122 | - throw new \RuntimeException("The database connection does not exists"); |
|
122 | + if (!array_key_exists($identifier, self::$drivers)) { |
|
123 | + throw new \RuntimeException("The database connection does not exists"); |
|
124 | + } |
|
123 | 125 | |
124 | 126 | return self::$drivers[$identifier]; |
125 | 127 | } |
@@ -135,8 +137,9 @@ discard block |
||
135 | 137 | */ |
136 | 138 | public static function hasDriver($identifier) |
137 | 139 | { |
138 | - if (!array_key_exists($identifier, self::$drivers)) |
|
139 | - return false; |
|
140 | + if (!array_key_exists($identifier, self::$drivers)) { |
|
141 | + return false; |
|
142 | + } |
|
140 | 143 | |
141 | 144 | return true; |
142 | 145 | } |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | { |
45 | 45 | $k++; |
46 | 46 | |
47 | - if (is_null($value)) |
|
48 | - $parsed_where[] = "$key IS NULL"; |
|
49 | - elseif ($value instanceof SQLFunction) |
|
50 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
51 | - elseif (is_array($value)) |
|
47 | + if (is_null($value)) { |
|
48 | + $parsed_where[] = "$key IS NULL"; |
|
49 | + } elseif ($value instanceof SQLFunction) { |
|
50 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
51 | + } elseif (is_array($value)) |
|
52 | 52 | { |
53 | 53 | $parsed_in = []; |
54 | 54 | |
@@ -71,8 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
74 | - } |
|
75 | - else |
|
74 | + } else |
|
76 | 75 | { |
77 | 76 | switch ($driver) |
78 | 77 | { |
@@ -90,18 +89,19 @@ discard block |
||
90 | 89 | } |
91 | 90 | |
92 | 91 | $where = "WHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
92 | + } else { |
|
93 | + $where = ""; |
|
93 | 94 | } |
94 | - else |
|
95 | - $where = ""; |
|
96 | 95 | |
97 | 96 | $table = $this->entity->getTableName(); |
98 | 97 | |
99 | 98 | $sql = "SELECT * \r\nFROM {$table}\r\n$where"; |
100 | 99 | |
101 | - if (count($bind_values)) |
|
102 | - $this->getDb()->execute($sql, $bind_values); |
|
103 | - else |
|
104 | - $this->getDb()->execute($sql); |
|
100 | + if (count($bind_values)) { |
|
101 | + $this->getDb()->execute($sql, $bind_values); |
|
102 | + } else { |
|
103 | + $this->getDb()->execute($sql); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | return $this->getDb()->getArrayResult(); |
107 | 107 | } |
@@ -118,8 +118,9 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function insert(Array $data) |
120 | 120 | { |
121 | - if (!count($data)) |
|
122 | - throw new \LogicException("Missing values for INSERT statement!"); |
|
121 | + if (!count($data)) { |
|
122 | + throw new \LogicException("Missing values for INSERT statement!"); |
|
123 | + } |
|
123 | 124 | |
124 | 125 | $bind_values = []; |
125 | 126 | |
@@ -142,11 +143,11 @@ discard block |
||
142 | 143 | continue; |
143 | 144 | } |
144 | 145 | |
145 | - if (is_null($value)) |
|
146 | - $value = "NULL"; |
|
147 | - elseif ($value instanceof SQLFunction) |
|
148 | - $value = $value->getStatement(); |
|
149 | - else { |
|
146 | + if (is_null($value)) { |
|
147 | + $value = "NULL"; |
|
148 | + } elseif ($value instanceof SQLFunction) { |
|
149 | + $value = $value->getStatement(); |
|
150 | + } else { |
|
150 | 151 | |
151 | 152 | switch ($driver) |
152 | 153 | { |
@@ -196,11 +197,13 @@ discard block |
||
196 | 197 | { |
197 | 198 | $parsed_set = []; |
198 | 199 | |
199 | - if (!count($set)) |
|
200 | - throw new \LogicException("You cannot update rows without SET clause"); |
|
200 | + if (!count($set)) { |
|
201 | + throw new \LogicException("You cannot update rows without SET clause"); |
|
202 | + } |
|
201 | 203 | |
202 | - if (!count($where)) |
|
203 | - throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
204 | + if (!count($where)) { |
|
205 | + throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
206 | + } |
|
204 | 207 | |
205 | 208 | $bind_values = []; |
206 | 209 | |
@@ -212,11 +215,11 @@ discard block |
||
212 | 215 | { |
213 | 216 | $k++; |
214 | 217 | |
215 | - if (is_null($value)) |
|
216 | - $parsed_set[] = "$key = NULL"; |
|
217 | - elseif ($value instanceof SQLFunction) |
|
218 | - $parsed_set[] = "$key = " . $value->getStatement(); |
|
219 | - elseif (is_array($value)) |
|
218 | + if (is_null($value)) { |
|
219 | + $parsed_set[] = "$key = NULL"; |
|
220 | + } elseif ($value instanceof SQLFunction) { |
|
221 | + $parsed_set[] = "$key = " . $value->getStatement(); |
|
222 | + } elseif (is_array($value)) |
|
220 | 223 | { |
221 | 224 | $parsed_in = []; |
222 | 225 | |
@@ -227,8 +230,9 @@ discard block |
||
227 | 230 | case 'Oci8': |
228 | 231 | |
229 | 232 | # [POSSIBLE BUG] - To Future revision (What about non-string values ?) |
230 | - if (is_string($in_value)) |
|
231 | - $parsed_in[] = ":$k"; |
|
233 | + if (is_string($in_value)) { |
|
234 | + $parsed_in[] = ":$k"; |
|
235 | + } |
|
232 | 236 | |
233 | 237 | $bind_values[":$k"] = $in_value; |
234 | 238 | break; |
@@ -243,8 +247,7 @@ discard block |
||
243 | 247 | } |
244 | 248 | |
245 | 249 | $parsed_set[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
246 | - } |
|
247 | - else |
|
250 | + } else |
|
248 | 251 | { |
249 | 252 | switch ($driver) |
250 | 253 | { |
@@ -269,11 +272,11 @@ discard block |
||
269 | 272 | { |
270 | 273 | $k++; |
271 | 274 | |
272 | - if (is_null($value)) |
|
273 | - $parsed_where[] = "$key IS NULL"; |
|
274 | - elseif ($value instanceof SQLFunction) |
|
275 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
276 | - elseif (is_array($value)) |
|
275 | + if (is_null($value)) { |
|
276 | + $parsed_where[] = "$key IS NULL"; |
|
277 | + } elseif ($value instanceof SQLFunction) { |
|
278 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
279 | + } elseif (is_array($value)) |
|
277 | 280 | { |
278 | 281 | $parsed_in = []; |
279 | 282 | |
@@ -296,8 +299,7 @@ discard block |
||
296 | 299 | } |
297 | 300 | |
298 | 301 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
299 | - } |
|
300 | - else |
|
302 | + } else |
|
301 | 303 | { |
302 | 304 | switch ($driver) |
303 | 305 | { |
@@ -349,11 +351,11 @@ discard block |
||
349 | 351 | { |
350 | 352 | $k++; |
351 | 353 | |
352 | - if (is_null($value)) |
|
353 | - $parsed_where[] = "$key IS NULL"; |
|
354 | - elseif ($value instanceof SQLFunction) |
|
355 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
356 | - elseif (is_array($value)) |
|
354 | + if (is_null($value)) { |
|
355 | + $parsed_where[] = "$key IS NULL"; |
|
356 | + } elseif ($value instanceof SQLFunction) { |
|
357 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
358 | + } elseif (is_array($value)) |
|
357 | 359 | { |
358 | 360 | $parsed_in = []; |
359 | 361 | |
@@ -376,8 +378,7 @@ discard block |
||
376 | 378 | } |
377 | 379 | |
378 | 380 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
379 | - } |
|
380 | - else |
|
381 | + } else |
|
381 | 382 | { |
382 | 383 | switch ($driver) |
383 | 384 | { |
@@ -395,9 +396,9 @@ discard block |
||
395 | 396 | } |
396 | 397 | |
397 | 398 | $where = "\r\nWHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
399 | + } else { |
|
400 | + throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
398 | 401 | } |
399 | - else |
|
400 | - throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
401 | 402 | |
402 | 403 | $table = $this->entity->getTableName(); |
403 | 404 |
@@ -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 | { |
@@ -70,8 +74,7 @@ discard block |
||
70 | 74 | * the warning message "Property access is not allowed yet". |
71 | 75 | */ |
72 | 76 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); |
73 | - } |
|
74 | - else |
|
77 | + } else |
|
75 | 78 | { |
76 | 79 | $this->dbconn = $conn; |
77 | 80 | $this->dbconn->set_charset($this->dbchar); |
@@ -118,13 +121,15 @@ discard block |
||
118 | 121 | |
119 | 122 | for ($i = 0; $i < $n_params; $i++) |
120 | 123 | { |
121 | - if (is_string($param_values[$i])) |
|
122 | - $bind_types .= 's'; |
|
123 | - else if(is_float($param_values[$i])) |
|
124 | - $bind_types .= 'd'; |
|
124 | + if (is_string($param_values[$i])) { |
|
125 | + $bind_types .= 's'; |
|
126 | + } else if(is_float($param_values[$i])) { |
|
127 | + $bind_types .= 'd'; |
|
128 | + } |
|
125 | 129 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
126 | - else |
|
127 | - $bind_types .= 's'; |
|
130 | + else { |
|
131 | + $bind_types .= 's'; |
|
132 | + } |
|
128 | 133 | |
129 | 134 | $bind_values[] = '$param_values[' . $i . ']'; |
130 | 135 | } |
@@ -137,8 +142,7 @@ discard block |
||
137 | 142 | if ($r) |
138 | 143 | { |
139 | 144 | } |
140 | - } |
|
141 | - else |
|
145 | + } else |
|
142 | 146 | { |
143 | 147 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
144 | 148 | |
@@ -167,28 +171,33 @@ discard block |
||
167 | 171 | * It is useful to prevent rollback transactions on insert statements because |
168 | 172 | * insert statement do not free results. |
169 | 173 | */ |
170 | - if ($res) |
|
171 | - $this->result = $res; |
|
174 | + if ($res) { |
|
175 | + $this->result = $res; |
|
176 | + } |
|
172 | 177 | } |
173 | 178 | |
174 | 179 | # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries |
175 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) |
|
176 | - $this->numRows = $this->result->num_rows; |
|
177 | - else |
|
180 | + if (is_object($this->result) && property_exists($this->result, 'num_rows')) { |
|
181 | + $this->numRows = $this->result->num_rows; |
|
182 | + } else |
|
178 | 183 | { |
179 | - if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) |
|
180 | - $this->rowsAffected = $this->dbconn->affected_rows; |
|
184 | + if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) { |
|
185 | + $this->rowsAffected = $this->dbconn->affected_rows; |
|
186 | + } |
|
181 | 187 | } |
182 | 188 | |
183 | 189 | # affected_rows return the same of num_rows on select statements! |
184 | - if ($this->numRows > 0) |
|
185 | - $this->rowsAffected = 0; |
|
190 | + if ($this->numRows > 0) { |
|
191 | + $this->rowsAffected = 0; |
|
192 | + } |
|
186 | 193 | |
187 | - if (property_exists($this->dbconn, 'field_count')) |
|
188 | - $this->numFields = $this->dbconn->field_count; |
|
194 | + if (property_exists($this->dbconn, 'field_count')) { |
|
195 | + $this->numFields = $this->dbconn->field_count; |
|
196 | + } |
|
189 | 197 | |
190 | - if ($this->transac_mode) |
|
191 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
198 | + if ($this->transac_mode) { |
|
199 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
200 | + } |
|
192 | 201 | |
193 | 202 | /* |
194 | 203 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, |
@@ -257,9 +266,8 @@ discard block |
||
257 | 266 | { |
258 | 267 | $data[] = $row; |
259 | 268 | } |
260 | - } |
|
261 | - else |
|
262 | - /* |
|
269 | + } else { |
|
270 | + /* |
|
263 | 271 | * "This kind of exception should lead directly to a fix in your code" |
264 | 272 | * So much production tests tell us this error is throwed because developers |
265 | 273 | * execute toArray() before execute(). |
@@ -267,6 +275,7 @@ discard block |
||
267 | 275 | * Ref: http://php.net/manual/en/class.logicexception.php |
268 | 276 | */ |
269 | 277 | throw new \LogicException('There are not data in the buffer!'); |
278 | + } |
|
270 | 279 | |
271 | 280 | $this->arrayResult = $data; |
272 | 281 | |
@@ -281,7 +290,8 @@ discard block |
||
281 | 290 | public function __destruct() |
282 | 291 | { |
283 | 292 | # prevent "Property access is not allowed yet" with @ on failure connections |
284 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
285 | - @$this->dbconn->close(); |
|
293 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
294 | + @$this->dbconn->close(); |
|
295 | + } |
|
286 | 296 | } |
287 | 297 | } |
288 | 298 | \ No newline at end of file |
@@ -33,15 +33,17 @@ discard block |
||
33 | 33 | { |
34 | 34 | $this->driverName = 'Oci8'; |
35 | 35 | |
36 | - if (!array_key_exists("dbchar", $options)) |
|
37 | - $options["dbchar"] = "AL32UTF8"; |
|
36 | + if (!array_key_exists("dbchar", $options)) { |
|
37 | + $options["dbchar"] = "AL32UTF8"; |
|
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,8 +56,9 @@ discard block |
||
54 | 56 | */ |
55 | 57 | public function connect() |
56 | 58 | { |
57 | - if (!extension_loaded('oci8')) |
|
58 | - throw new \RuntimeException("The Oci8 extension is not loaded"); |
|
59 | + if (!extension_loaded('oci8')) { |
|
60 | + throw new \RuntimeException("The Oci8 extension is not loaded"); |
|
61 | + } |
|
59 | 62 | |
60 | 63 | $connection_string = (is_null($this->dbhost) || empty($this->dbhost)) |
61 | 64 | ? $this->dbname |
@@ -108,14 +111,15 @@ discard block |
||
108 | 111 | ]; |
109 | 112 | |
110 | 113 | $this->error($error["message"]); |
114 | + } else { |
|
115 | + $this->error($error["code"], $error["message"]); |
|
111 | 116 | } |
112 | - else |
|
113 | - $this->error($error["code"], $error["message"]); |
|
114 | 117 | |
115 | - if (array_key_exists("code", $error)) |
|
116 | - throw new Exception\InvalidQueryException($error["message"], $error["code"]); |
|
117 | - else |
|
118 | - throw new Exception\InvalidQueryException($error["message"]); |
|
118 | + if (array_key_exists("code", $error)) { |
|
119 | + throw new Exception\InvalidQueryException($error["message"], $error["code"]); |
|
120 | + } else { |
|
121 | + throw new Exception\InvalidQueryException($error["message"]); |
|
122 | + } |
|
119 | 123 | } |
120 | 124 | |
121 | 125 | # Bound variables |
@@ -155,8 +159,9 @@ discard block |
||
155 | 159 | $this->numRows = count($rows); |
156 | 160 | $this->numFields = oci_num_fields($stid); |
157 | 161 | |
158 | - if ($this->transac_mode) |
|
159 | - $this->transac_result = is_null($this->transac_result) ? $stid: $this->transac_result && $stid; |
|
162 | + if ($this->transac_mode) { |
|
163 | + $this->transac_result = is_null($this->transac_result) ? $stid: $this->transac_result && $stid; |
|
164 | + } |
|
160 | 165 | |
161 | 166 | $this->result = $stid; |
162 | 167 | |
@@ -205,9 +210,8 @@ discard block |
||
205 | 210 | { |
206 | 211 | $data[] = $row; |
207 | 212 | } |
208 | - } |
|
209 | - else |
|
210 | - /* |
|
213 | + } else { |
|
214 | + /* |
|
211 | 215 | * "This kind of exception should lead directly to a fix in your code" |
212 | 216 | * So much production tests tell us this error is throwed because developers |
213 | 217 | * execute toArray() before execute(). |
@@ -215,6 +219,7 @@ discard block |
||
215 | 219 | * Ref: http://php.net/manual/en/class.logicexception.php |
216 | 220 | */ |
217 | 221 | throw new \LogicException('There are not data in the buffer!'); |
222 | + } |
|
218 | 223 | |
219 | 224 | $this->arrayResult = $data; |
220 | 225 | |
@@ -228,7 +233,8 @@ discard block |
||
228 | 233 | */ |
229 | 234 | public function __destruct() |
230 | 235 | { |
231 | - if ($this->dbconn) |
|
232 | - oci_close($this->dbconn); |
|
236 | + if ($this->dbconn) { |
|
237 | + oci_close($this->dbconn); |
|
238 | + } |
|
233 | 239 | } |
234 | 240 | } |
235 | 241 | \ No newline at end of file |
@@ -34,14 +34,16 @@ |
||
34 | 34 | "Sqlsrv" => "Drone\Db\Driver\SQLServer", |
35 | 35 | ]; |
36 | 36 | |
37 | - if (!array_key_exists('driver', $connection_options)) |
|
38 | - throw new \RuntimeException("The database driver key has not been declared"); |
|
37 | + if (!array_key_exists('driver', $connection_options)) { |
|
38 | + throw new \RuntimeException("The database driver key has not been declared"); |
|
39 | + } |
|
39 | 40 | |
40 | 41 | $drv = $connection_options["driver"]; |
41 | 42 | |
42 | - if (array_key_exists($drv, $drivers)) |
|
43 | - return new $drivers[$drv]($connection_options); |
|
44 | - else |
|
45 | - throw new \RuntimeException("The database driver does not exists"); |
|
43 | + if (array_key_exists($drv, $drivers)) { |
|
44 | + return new $drivers[$drv]($connection_options); |
|
45 | + } else { |
|
46 | + throw new \RuntimeException("The database driver does not exists"); |
|
47 | + } |
|
46 | 48 | } |
47 | 49 | } |
48 | 50 | \ No newline at end of file |
@@ -33,15 +33,17 @@ discard block |
||
33 | 33 | { |
34 | 34 | $this->driverName = 'Sqlsrv'; |
35 | 35 | |
36 | - if (!array_key_exists("dbchar", $options)) |
|
37 | - $options["dbchar"] = "UTF-8"; |
|
36 | + if (!array_key_exists("dbchar", $options)) { |
|
37 | + $options["dbchar"] = "UTF-8"; |
|
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,11 +56,13 @@ discard block |
||
54 | 56 | */ |
55 | 57 | public function connect() |
56 | 58 | { |
57 | - if (!extension_loaded('sqlsrv')) |
|
58 | - throw new \RuntimeException("The Sqlsrv extension is not loaded"); |
|
59 | + if (!extension_loaded('sqlsrv')) { |
|
60 | + throw new \RuntimeException("The Sqlsrv extension is not loaded"); |
|
61 | + } |
|
59 | 62 | |
60 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
61 | - $this->dbhost .= ', ' . $this->dbport; |
|
63 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
64 | + $this->dbhost .= ', ' . $this->dbport; |
|
65 | + } |
|
62 | 66 | |
63 | 67 | $db_info = array("Database" => $this->dbname, "UID" => $this->dbuser, "PWD" => $this->dbpass, "CharacterSet" => $this->dbchar); |
64 | 68 | $conn = sqlsrv_connect($this->dbhost, $db_info); |
@@ -139,13 +143,13 @@ discard block |
||
139 | 143 | } |
140 | 144 | |
141 | 145 | $exec = sqlsrv_execute($stmt); |
142 | - } |
|
143 | - else |
|
146 | + } else |
|
144 | 147 | { |
145 | - if ($isSelectStm) |
|
146 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
147 | - else |
|
148 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params); |
|
148 | + if ($isSelectStm) { |
|
149 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
150 | + } else { |
|
151 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params); |
|
152 | + } |
|
149 | 153 | } |
150 | 154 | |
151 | 155 | if ($exec === false) |
@@ -165,11 +169,13 @@ discard block |
||
165 | 169 | $this->numRows = sqlsrv_has_rows($this->result) ? sqlsrv_num_rows($this->result) : $this->numRows; |
166 | 170 | $this->numFields = sqlsrv_num_fields($this->result); |
167 | 171 | |
168 | - if ($isInsertStm || $isUpdateStm || $isDeleteStm) |
|
169 | - $this->rowsAffected = sqlsrv_rows_affected($this->result); |
|
172 | + if ($isInsertStm || $isUpdateStm || $isDeleteStm) { |
|
173 | + $this->rowsAffected = sqlsrv_rows_affected($this->result); |
|
174 | + } |
|
170 | 175 | |
171 | - if ($this->transac_mode) |
|
172 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
176 | + if ($this->transac_mode) { |
|
177 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
178 | + } |
|
173 | 179 | |
174 | 180 | return $this->result; |
175 | 181 | } |
@@ -236,9 +242,8 @@ discard block |
||
236 | 242 | { |
237 | 243 | $data[] = $row; |
238 | 244 | } |
239 | - } |
|
240 | - else |
|
241 | - /* |
|
245 | + } else { |
|
246 | + /* |
|
242 | 247 | * "This kind of exception should lead directly to a fix in your code" |
243 | 248 | * So much production tests tell us this error is throwed because developers |
244 | 249 | * execute toArray() before execute(). |
@@ -246,6 +251,7 @@ discard block |
||
246 | 251 | * Ref: http://php.net/manual/en/class.logicexception.php |
247 | 252 | */ |
248 | 253 | throw new \LogicException('There are not data in the buffer!'); |
254 | + } |
|
249 | 255 | |
250 | 256 | $this->arrayResult = $data; |
251 | 257 | |
@@ -259,7 +265,8 @@ discard block |
||
259 | 265 | */ |
260 | 266 | public function __destruct() |
261 | 267 | { |
262 | - if ($this->dbconn) |
|
263 | - sqlsrv_close($this->dbconn); |
|
268 | + if ($this->dbconn) { |
|
269 | + sqlsrv_close($this->dbconn); |
|
270 | + } |
|
264 | 271 | } |
265 | 272 | } |
266 | 273 | \ No newline at end of file |