Skip to content

Commit 8ee4c74

Browse files
committed
More breaking changes, and corrections
- class properties that was accessible with `get/set`, now PSR 1 camelCase - update class libraries and tests to match - renamed `select` of `ez_mysqli` to `dbSelect` - update tests to match `dbSelect` - renamed class method `selecting` to `select` - update tests to match `select`
1 parent 3fd6fec commit 8ee4c74

25 files changed

+418
-413
lines changed

lib/Database.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function __wakeup()
3131
/**
3232
* Initialize and connect a vendor database.
3333
*
34-
* @param mixed $vendor - SQL driver
35-
* @param mixed $setting - SQL connection parameters
36-
* @param mixed $tag - Store the instance for later use
34+
* @param string $vendor SQL driver
35+
* @param array $setting SQL connection parameters
36+
* @param string $tag Store the instance for later use
3737
* @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli
3838
*/
3939
public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null)

lib/Database/ez_mysqli.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface
1414
{
1515
private $return_val = 0;
1616
private $is_insert = false;
17-
private $shortcutUsed = false;
1817
private $isTransactional = false;
1918

2019
/**
@@ -34,6 +33,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface
3433
* @var ConfigInterface
3534
*/
3635
private $database;
36+
protected $shortcutUsed = false;
3737

3838
public function __construct(ConfigInterface $settings = null)
3939
{
@@ -82,7 +82,7 @@ public function quick_connect(
8282
$charset = empty($charset) ? $this->database->getCharset() : $charset;
8383

8484
if (!$this->connect($user, $password, $host, (int) $port, $charset));
85-
else if (!$this->select($name, $charset));
85+
else if (!$this->dbSelect($name, $charset));
8686

8787
return $this->_connected;
8888
} // quick_connect
@@ -125,13 +125,13 @@ public function connect(
125125
} // connect
126126

127127
/**
128-
* Try to select a mySQL database
128+
* Try to select the default database for mySQL
129129
*
130130
* @param string $name The name of the database
131131
* @param string $charset Encoding of the database
132132
* @return boolean
133133
*/
134-
public function select($name = '', $charset = '')
134+
public function dbSelect($name = '', $charset = '')
135135
{
136136
$name = empty($name) ? $this->database->getName() : $name;
137137
try {
@@ -213,9 +213,9 @@ private function fetch_prepared_result(&$stmt, $query)
213213
if (\preg_match("/^(insert|delete|update|replace)\s+/i", $query)) {
214214
$this->_affectedRows = \mysqli_stmt_affected_rows($stmt);
215215

216-
// Take note of the insert_id
216+
// Take note of the insert id
217217
if (\preg_match("/^(insert|replace)\s+/i", $query)) {
218-
$this->insert_id = $stmt->insert_id;
218+
$this->insertId = $stmt->insert_id;
219219
}
220220
} else {
221221
$this->_affectedRows = $stmt->num_rows;
@@ -226,7 +226,7 @@ private function fetch_prepared_result(&$stmt, $query)
226226
while ($field = $meta->fetch_field()) {
227227
$col_info[$field->name] = "";
228228
$variables[$field->name] = &$col_info[$field->name];
229-
$this->col_info[$x] = $field;
229+
$this->colInfo[$x] = $field;
230230
$x++;
231231
}
232232

@@ -241,7 +241,7 @@ private function fetch_prepared_result(&$stmt, $query)
241241
foreach ($variables as $key => $value) {
242242
$resultObject->$key = $value;
243243
}
244-
$this->last_result[$i] = $resultObject;
244+
$this->lastResult[$i] = $resultObject;
245245
$i++;
246246
}
247247
}
@@ -252,7 +252,7 @@ private function fetch_prepared_result(&$stmt, $query)
252252
$this->register_error($str);
253253

254254
// If debug ALL queries
255-
$this->trace || $this->debug_all ? $this->debug() : null;
255+
$this->trace || $this->debugAll ? $this->debug() : null;
256256
return false;
257257
}
258258

@@ -263,7 +263,7 @@ private function fetch_prepared_result(&$stmt, $query)
263263
$this->store_cache($query, $is_insert);
264264

265265
// If debug ALL queries
266-
$this->trace || $this->debug_all ? $this->debug() : null;
266+
$this->trace || $this->debugAll ? $this->debug() : null;
267267

268268
return $return_val;
269269
}
@@ -283,7 +283,7 @@ public function query_prepared(string $query, array $param = null)
283283
$stmt = $this->dbh->prepare($query);
284284
if (!$stmt instanceof \mysqli_stmt) {
285285
if ($this->isTransactional)
286-
throw new \Exception($this->getLast_Error());
286+
throw new \Exception($this->lastError);
287287

288288
return false;
289289
}
@@ -339,7 +339,7 @@ private function processQueryResult(string $query, $result = null)
339339
$this->register_error($str);
340340

341341
// If debug ALL queries
342-
$this->trace || $this->debug_all ? $this->debug() : null;
342+
$this->trace || $this->debugAll ? $this->debug() : null;
343343
return false;
344344
}
345345

@@ -351,7 +351,7 @@ private function processQueryResult(string $query, $result = null)
351351

352352
// Take note of the insert_id
353353
if (\preg_match("/^(insert|replace)\s+/i", $query)) {
354-
$this->insert_id = \mysqli_insert_id($this->dbh);
354+
$this->insertId = \mysqli_insert_id($this->dbh);
355355
}
356356

357357
// Return number of rows affected
@@ -363,25 +363,25 @@ private function processQueryResult(string $query, $result = null)
363363
// Take note of column info
364364
$i = 0;
365365
while ($i < \mysqli_num_fields($this->result)) {
366-
$this->col_info[$i] = \mysqli_fetch_field($this->result);
366+
$this->colInfo[$i] = \mysqli_fetch_field($this->result);
367367
$i++;
368368
}
369369

370370
// Store Query Results
371371
$num_rows = 0;
372372
while ($row = \mysqli_fetch_object($this->result)) {
373373
// Store results as an objects within main array
374-
$this->last_result[$num_rows] = $row;
374+
$this->lastResult[$num_rows] = $row;
375375
$num_rows++;
376376
}
377377

378378
\mysqli_free_result($this->result);
379379

380380
// Log number of rows the query returned
381-
$this->num_rows = $num_rows;
381+
$this->numRows = $num_rows;
382382

383383
// Return number of rows selected
384-
$this->return_val = $this->num_rows;
384+
$this->return_val = $this->numRows;
385385
}
386386
}
387387
}
@@ -415,10 +415,10 @@ public function query(string $query, bool $use_prepare = false)
415415
$this->log_query("\$db->query(\"$query\")");
416416

417417
// Keep track of the last query for debug..
418-
$this->last_query = $query;
418+
$this->lastQuery = $query;
419419

420420
// Count how many queries there have been
421-
$this->num_queries++;
421+
$this->numQueries++;
422422

423423
// Use core file cache function
424424
if ($cache = $this->get_cache($query)) {
@@ -441,7 +441,7 @@ public function query(string $query, bool $use_prepare = false)
441441

442442
if ($this->processQueryResult($query) === false) {
443443
if ($this->isTransactional)
444-
throw new \Exception($this->getLast_Error());
444+
throw new \Exception($this->lastError);
445445

446446
return false;
447447
}
@@ -450,7 +450,7 @@ public function query(string $query, bool $use_prepare = false)
450450
$this->store_cache($query, $this->is_insert);
451451

452452
// If debug ALL queries
453-
$this->trace || $this->debug_all ? $this->debug() : null;
453+
$this->trace || $this->debugAll ? $this->debug() : null;
454454

455455
return $this->return_val;
456456
} // query
@@ -515,7 +515,7 @@ public function getCharset()
515515
}
516516

517517
/**
518-
* Returns the last inserted auto-increment
518+
* Returns the last inserted Id - auto generated
519519
*
520520
* @return int
521521
*/
@@ -531,7 +531,7 @@ public function beginTransaction()
531531
{
532532
/* turn autocommit off */
533533
$this->dbh->autocommit(false);
534-
$this->dbh->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
534+
$this->dbh->begin_transaction(\MYSQLI_TRANS_START_READ_WRITE);
535535
$this->isTransactional = true;
536536
}
537537

lib/Database/ez_pdo.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace ezsql\Database;
66

77
use Exception;
8-
use ezsql\ezQuery;
98
use ezsql\ezsqlModel;
109
use ezsql\ConfigInterface;
1110
use ezsql\DatabaseInterface;
@@ -222,7 +221,7 @@ public function catch_error()
222221

223222
$error_str = \substr($error_str, 0, -2);
224223

225-
$this->register_error($error_str . ' ' . $this->last_query);
224+
$this->register_error($error_str . ' ' . $this->lastQuery);
226225

227226
return true;
228227
}
@@ -247,14 +246,14 @@ public function query_prepared(string $query, array $param = null, $isSelect = f
247246
try {
248247
while ($row = @$stmt->fetch(\PDO::FETCH_ASSOC)) {
249248
// Store results as an objects within main array
250-
$this->last_result[$num_rows] = (object) $row;
249+
$this->lastResult[$num_rows] = (object) $row;
251250
$num_rows++;
252251
}
253252
} catch (\Throwable $ex) {
254253
//
255254
}
256255

257-
$this->num_rows = $num_rows;
256+
$this->numRows = $num_rows;
258257
}
259258

260259
$return = ($isSelect) ? $stmt : $result;
@@ -290,16 +289,16 @@ private function processResult(string $query, $result = null, bool $isSelect = f
290289
$col_count = $result->columnCount();
291290
for ($i = 0; $i < $col_count; $i++) {
292291
// Start DEBUG by psc!
293-
$this->col_info[$i] = new \stdClass();
292+
$this->colInfo[$i] = new \stdClass();
294293
// End DEBUG by psc
295294
if ($meta = $result->getColumnMeta($i)) {
296-
$this->col_info[$i]->name = $meta['name'];
297-
$this->col_info[$i]->type = $meta['native_type'];
298-
$this->col_info[$i]->max_length = '';
295+
$this->colInfo[$i]->name = $meta['name'];
296+
$this->colInfo[$i]->type = $meta['native_type'];
297+
$this->colInfo[$i]->max_length = '';
299298
} else {
300-
$this->col_info[$i]->name = 'undefined';
301-
$this->col_info[$i]->type = 'undefined';
302-
$this->col_info[$i]->max_length = '';
299+
$this->colInfo[$i]->name = 'undefined';
300+
$this->colInfo[$i]->type = 'undefined';
301+
$this->colInfo[$i]->max_length = '';
303302
}
304303
}
305304

@@ -308,18 +307,18 @@ private function processResult(string $query, $result = null, bool $isSelect = f
308307
try {
309308
while ($row = @$result->fetch(\PDO::FETCH_ASSOC)) {
310309
// Store results as an objects within main array
311-
$this->last_result[$num_rows] = (object) $row;
310+
$this->lastResult[$num_rows] = (object) $row;
312311
$num_rows++;
313312
}
314313
} catch (\Throwable $ex) {
315314
//
316315
}
317316

318317
// Log number of rows the query returned
319-
$this->num_rows = empty($num_rows) ? $this->num_rows : $num_rows;
318+
$this->numRows = empty($num_rows) ? $this->numRows : $num_rows;
320319

321320
// Return number of rows selected
322-
$this->return_val = $this->num_rows;
321+
$this->return_val = $this->numRows;
323322
}
324323
} else {
325324
$this->is_insert = true;
@@ -330,7 +329,7 @@ private function processResult(string $query, $result = null, bool $isSelect = f
330329
try {
331330
// Take note of the insert_id
332331
if (\preg_match("/^(insert|replace)\s+/i", $query)) {
333-
$this->insert_id = @$this->dbh->lastInsertId();
332+
$this->insertId = @$this->dbh->lastInsertId();
334333
}
335334
} catch (\Throwable $ex) {
336335
//
@@ -418,21 +417,21 @@ public function query(string $query, bool $use_prepare = false)
418417
$this->log_query("\$db->query(\"$query\")");
419418

420419
// Keep track of the last query for debug..
421-
$this->last_query = $query;
420+
$this->lastQuery = $query;
422421

423-
$this->num_queries++;
422+
$this->numQueries++;
424423

425424
// Start timer
426-
$this->timer_start($this->num_queries);
425+
$this->timer_start($this->numQueries);
427426

428427
// Use core file cache function
429428
if ($cache = $this->get_cache($query)) {
430429
// Keep tack of how long all queries have taken
431-
$this->timer_update_global($this->num_queries);
430+
$this->timer_update_global($this->numQueries);
432431

433432
// Trace all queries
434-
if ($this->use_trace_log) {
435-
$this->trace_log[] = $this->debug(false);
433+
if ($this->useTraceLog) {
434+
$this->traceLog[] = $this->debug(false);
436435
}
437436

438437
return $cache;
@@ -460,14 +459,14 @@ public function query(string $query, bool $use_prepare = false)
460459
$this->store_cache($query, $this->is_insert);
461460

462461
// If debug ALL queries
463-
$this->trace || $this->debug_all ? $this->debug() : null;
462+
$this->trace || $this->debugAll ? $this->debug() : null;
464463

465464
// Keep tack of how long all queries have taken
466-
$this->timer_update_global($this->num_queries);
465+
$this->timer_update_global($this->numQueries);
467466

468467
// Trace all queries
469-
if ($this->use_trace_log) {
470-
$this->trace_log[] = $this->debug(false);
468+
if ($this->useTraceLog) {
469+
$this->traceLog[] = $this->debug(false);
471470
}
472471

473472
return $this->return_val;

0 commit comments

Comments
 (0)