Skip to content

Commit aad9c20

Browse files
committed
Use static:: instead of self:: for the MySQL class
1 parent e2468ce commit aad9c20

1 file changed

Lines changed: 50 additions & 50 deletions

File tree

src/IO/Database/MySQL.php

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ class MySQL
8888
* Attempts to make, store, and return a PDO connection.
8989
* - By default will use the label provided by static::getDefaultLabel()
9090
* - The label corresponds to a config in /config/db.php
91-
* - Also sets timezone on the connection based on self::$Timezone
92-
* - Sets self::$Connections[$label] with the connection after connecting.
93-
* - If self::$Connections[$label] already exists it will return that.
91+
* - Also sets timezone on the connection based on static::$Timezone
92+
* - Sets static::$Connections[$label] with the connection after connecting.
93+
* - If static::$Connections[$label] already exists it will return that.
9494
*
9595
* @param string|null $label A specific connection.
9696
* @return PDO A PDO connection
9797
*
9898
* @throws \Exception
9999
*
100-
* @uses self::$Connections
100+
* @uses static::$Connections
101101
* @uses static::getDefaultLabel()
102-
* @uses self::$Timezone
102+
* @uses static::$Timezone
103103
* @uses PDO
104104
*/
105105
public static function getConnection($label=null)
@@ -108,7 +108,7 @@ public static function getConnection($label=null)
108108
$label = static::getDefaultLabel();
109109
}
110110

111-
if (!isset(self::$Connections[$label])) {
111+
if (!isset(static::$Connections[$label])) {
112112
static::config();
113113

114114
$config = array_merge([
@@ -126,17 +126,17 @@ public static function getConnection($label=null)
126126

127127
try {
128128
// try to initiate connection
129-
self::$Connections[$label] = new PDO($DSN, $config['username'], $config['password']);
129+
static::$Connections[$label] = new PDO($DSN, $config['username'], $config['password']);
130130
} catch (\PDOException $e) {
131131
throw new \Exception('PDO failed to connect on config "'.$label.'" '.$DSN);
132132
}
133133

134134
// set timezone
135-
$q = self::$Connections[$label]->prepare('SET time_zone=?');
136-
$q->execute([self::$TimeZone]);
135+
$q = static::$Connections[$label]->prepare('SET time_zone=?');
136+
$q->execute([static::$TimeZone]);
137137
}
138138

139-
return self::$Connections[$label];
139+
return static::$Connections[$label];
140140
}
141141

142142
/**
@@ -169,7 +169,7 @@ public static function escape($data)
169169
*/
170170
public static function affectedRows()
171171
{
172-
return self::$LastStatement->rowCount();
172+
return static::$LastStatement->rowCount();
173173
}
174174

175175
/**
@@ -180,7 +180,7 @@ public static function affectedRows()
180180
*/
181181
public static function foundRows()
182182
{
183-
return self::oneValue('SELECT FOUND_ROWS()');
183+
return static::oneValue('SELECT FOUND_ROWS()');
184184
}
185185

186186
/**
@@ -190,7 +190,7 @@ public static function foundRows()
190190
*/
191191
public static function insertID()
192192
{
193-
return self::getConnection()->lastInsertId();
193+
return static::getConnection()->lastInsertId();
194194
}
195195

196196
/**
@@ -206,7 +206,7 @@ public static function insertID()
206206
*/
207207
public static function prepareQuery($query, $parameters = [])
208208
{
209-
return self::preprocessQuery($query, $parameters);
209+
return static::preprocessQuery($query, $parameters);
210210
}
211211

212212
/**
@@ -216,18 +216,18 @@ public static function prepareQuery($query, $parameters = [])
216216
*
217217
* @param string $query A MySQL query
218218
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
219-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
219+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
220220
* @return void
221221
*/
222222
public static function nonQuery($query, $parameters = [], $errorHandler = null)
223223
{
224-
$query = self::preprocessQuery($query, $parameters);
224+
$query = static::preprocessQuery($query, $parameters);
225225

226226
// start query log
227-
$queryLog = self::startQueryLog($query);
227+
$queryLog = static::startQueryLog($query);
228228

229229
// execute query
230-
$Statement = self::getConnection()->query($query);
230+
$Statement = static::getConnection()->query($query);
231231

232232
if ($Statement) {
233233

@@ -236,49 +236,49 @@ public static function nonQuery($query, $parameters = [], $errorHandler = null)
236236

237237
// handle query error
238238
if ($ErrorInfo[0] != '00000') {
239-
self::handleError($query, $queryLog, $errorHandler);
239+
static::handleError($query, $queryLog, $errorHandler);
240240
}
241241
} else {
242242
// check for errors
243-
$ErrorInfo = self::getConnection()->errorInfo();
243+
$ErrorInfo = static::getConnection()->errorInfo();
244244

245245
// handle query error
246246
if ($ErrorInfo[0] != '00000') {
247-
self::handleError($query, $queryLog, $errorHandler);
247+
static::handleError($query, $queryLog, $errorHandler);
248248
}
249249
}
250250

251251
static::$LastStatement = $Statement;
252252

253253
// finish query log
254-
self::finishQueryLog($queryLog);
254+
static::finishQueryLog($queryLog);
255255
}
256256

257257
/**
258258
* Run a query and returns a PDO statement
259259
*
260260
* @param string $query A MySQL query
261261
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
262-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
262+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
263263
* @return \PDOStatement
264264
*/
265265
public static function query($query, $parameters = [], $errorHandler = null)
266266
{
267-
$query = self::preprocessQuery($query, $parameters);
267+
$query = static::preprocessQuery($query, $parameters);
268268

269269
// start query log
270-
$queryLog = self::startQueryLog($query);
270+
$queryLog = static::startQueryLog($query);
271271

272272
// execute query
273-
$Statement = self::getConnection()->query($query);
273+
$Statement = static::getConnection()->query($query);
274274

275275
if (!$Statement) {
276276
// check for errors
277-
$ErrorInfo = self::getConnection()->errorInfo();
277+
$ErrorInfo = static::getConnection()->errorInfo();
278278

279279
// handle query error
280280
if ($ErrorInfo[0] != '00000') {
281-
$ErrorOutput = self::handleError($query, $queryLog, $errorHandler);
281+
$ErrorOutput = static::handleError($query, $queryLog, $errorHandler);
282282

283283
if (is_a($ErrorOutput, 'PDOStatement')) {
284284
$Statement = $ErrorOutput;
@@ -289,7 +289,7 @@ public static function query($query, $parameters = [], $errorHandler = null)
289289
static::$LastStatement = $Statement;
290290

291291
// finish query log
292-
self::finishQueryLog($queryLog);
292+
static::finishQueryLog($queryLog);
293293

294294
return $Statement;
295295
}
@@ -305,13 +305,13 @@ public static function query($query, $parameters = [], $errorHandler = null)
305305
* @param string $query A MySQL query
306306
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
307307
* @param string $nullKey Optional fallback column to use as an index if the $tableKey param isn't found in a returned record.
308-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
308+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
309309
* @return array Result from query or an empty array if nothing found.
310310
*/
311311
public static function table($tableKey, $query, $parameters = [], $nullKey = '', $errorHandler = null)
312312
{
313313
// execute query
314-
$result = self::query($query, $parameters, $errorHandler);
314+
$result = static::query($query, $parameters, $errorHandler);
315315

316316
$records = [];
317317
while ($record = $result->fetch(PDO::FETCH_ASSOC)) {
@@ -326,13 +326,13 @@ public static function table($tableKey, $query, $parameters = [], $nullKey = '',
326326
*
327327
* @param string $query A MySQL query
328328
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
329-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
329+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
330330
* @return array Result from query or an empty array if nothing found.
331331
*/
332332
public static function allRecords($query, $parameters = [], $errorHandler = null)
333333
{
334334
// execute query
335-
$result = self::query($query, $parameters, $errorHandler);
335+
$result = static::query($query, $parameters, $errorHandler);
336336

337337
$records = [];
338338
while ($record = $result->fetch(PDO::FETCH_ASSOC)) {
@@ -349,13 +349,13 @@ public static function allRecords($query, $parameters = [], $errorHandler = null
349349
* @param string $valueKey The name of the column you want.
350350
* @param string $query A MySQL query
351351
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
352-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
352+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
353353
* @return array The column provided in $valueKey from each found record combined as an array. Will be an empty array if no records are found.
354354
*/
355355
public static function allValues($valueKey, $query, $parameters = [], $errorHandler = null)
356356
{
357357
// execute query
358-
$result = self::query($query, $parameters, $errorHandler);
358+
$result = static::query($query, $parameters, $errorHandler);
359359

360360
$records = [];
361361
while ($record = $result->fetch(PDO::FETCH_ASSOC)) {
@@ -366,16 +366,16 @@ public static function allValues($valueKey, $query, $parameters = [], $errorHand
366366
}
367367

368368
/**
369-
* Unsets self::$_record_cache[$cacheKey]
369+
* Unsets static::$_record_cache[$cacheKey]
370370
*
371371
* @param string $cacheKey
372372
* @return void
373373
*
374-
* @uses self::$_record_cache
374+
* @uses static::$_record_cache
375375
*/
376376
public static function clearCachedRecord($cacheKey)
377377
{
378-
unset(self::$_record_cache[$cacheKey]);
378+
unset(static::$_record_cache[$cacheKey]);
379379
}
380380

381381
/**
@@ -386,29 +386,29 @@ public static function clearCachedRecord($cacheKey)
386386
* @param string $cacheKey A key for the cache to use for this query. If the key is found in the existing cache will return that instead of running the query.
387387
* @param string $query A MySQL query
388388
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
389-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
389+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
390390
* @return array Result from query or an empty array if nothing found.
391391
*
392-
* @uses self::$_record_cache
392+
* @uses static::$_record_cache
393393
*/
394394
public static function oneRecordCached($cacheKey, $query, $parameters = [], $errorHandler = null)
395395
{
396396

397397
// check for cached record
398-
if (array_key_exists($cacheKey, self::$_record_cache)) {
398+
if (array_key_exists($cacheKey, static::$_record_cache)) {
399399
// return cache hit
400-
return self::$_record_cache[$cacheKey];
400+
return static::$_record_cache[$cacheKey];
401401
}
402402

403403
// preprocess and execute query
404-
$result = self::query($query, $parameters, $errorHandler);
404+
$result = static::query($query, $parameters, $errorHandler);
405405

406406
// get record
407407
$record = $result->fetch(PDO::FETCH_ASSOC);
408408

409409
// save record to cache
410410
if ($cacheKey) {
411-
self::$_record_cache[$cacheKey] = $record;
411+
static::$_record_cache[$cacheKey] = $record;
412412
}
413413

414414
// return record
@@ -423,13 +423,13 @@ public static function oneRecordCached($cacheKey, $query, $parameters = [], $err
423423
*
424424
* @param string $query A MySQL query
425425
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
426-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
426+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
427427
* @return array Result from query or an empty array if nothing found.
428428
*/
429429
public static function oneRecord($query, $parameters = [], $errorHandler = null)
430430
{
431431
// preprocess and execute query
432-
$result = self::query($query, $parameters, $errorHandler);
432+
$result = static::query($query, $parameters, $errorHandler);
433433

434434
// get record
435435
$record = $result->fetch(PDO::FETCH_ASSOC);
@@ -443,13 +443,13 @@ public static function oneRecord($query, $parameters = [], $errorHandler = null)
443443
*
444444
* @param string $query A MySQL query
445445
* @param array|string $parameters Optional parameters for vsprintf (array) or sprintf (string) to use for formatting the query.
446-
* @param callable $errorHandler A callback that will run in the event of an error instead of self::handleError
446+
* @param callable $errorHandler A callback that will run in the event of an error instead of static::handleError
447447
* @return string|false First field from the first record from a query or false if nothing found.
448448
*/
449449
public static function oneValue($query, $parameters = [], $errorHandler = null)
450450
{
451451
// get the first record
452-
$record = self::oneRecord($query, $parameters, $errorHandler);
452+
$record = static::oneRecord($query, $parameters, $errorHandler);
453453

454454
if ($record) {
455455
// return first value of the record
@@ -481,7 +481,7 @@ public static function handleError($query = '', $queryLog = false, $errorHandler
481481
if ($queryLog) {
482482
$error = static::getConnection()->errorInfo();
483483
$queryLog['error'] = $error[2];
484-
self::finishQueryLog($queryLog);
484+
static::finishQueryLog($queryLog);
485485
}
486486

487487
// get error message
@@ -494,7 +494,7 @@ public static function handleError($query = '', $queryLog = false, $errorHandler
494494
$Handler->addDataTable("Query Information", [
495495
'Query' => $query,
496496
'Error' => $message,
497-
'ErrorCode' => self::getConnection()->errorCode(),
497+
'ErrorCode' => static::getConnection()->errorCode(),
498498
]);
499499

500500
\Divergence\App::$whoops->pushHandler($Handler);

0 commit comments

Comments
 (0)