@@ -23,7 +23,7 @@ public function __construct() {
23
23
$ this ->offset = '' ;
24
24
$ this ->where = [
25
25
'query_string ' => null ,
26
- 'binding ' => null
26
+ 'bindings ' => null ,
27
27
];
28
28
}
29
29
@@ -33,8 +33,7 @@ public function __construct() {
33
33
private static function init_db () {
34
34
try {
35
35
self ::$ pdo = new PDO ( 'sqlite: ' . DB );
36
- }
37
- catch ( PDOException $ exception ) {
36
+ } catch ( PDOException $ exception ) {
38
37
EE ::error ( $ exception ->getMessage () );
39
38
}
40
39
@@ -105,8 +104,7 @@ private static function create_required_tables() {
105
104
106
105
try {
107
106
self ::$ pdo ->exec ( $ query );
108
- }
109
- catch ( PDOException $ exception ) {
107
+ } catch ( PDOException $ exception ) {
110
108
EE ::error ( 'Encountered Error while creating table: ' . $ exception ->getMessage () );
111
109
}
112
110
}
@@ -121,8 +119,8 @@ private static function create_required_tables() {
121
119
* @return bool Success.
122
120
*/
123
121
public static function site_in_db ( $ site_name ) {
124
-
125
- $ site = self :: table ( 'sites ' )
122
+ $ db = new EE_DB ();
123
+ $ site = $ db -> table ( 'sites ' )
126
124
->select ( 'id ' )
127
125
->where ( 'sitename ' , $ site_name )
128
126
->first ();
@@ -141,7 +139,7 @@ public static function site_in_db( $site_name ) {
141
139
* @throws Exception
142
140
*/
143
141
public function first () {
144
- $ pdo_statement = $ this ->common_retrival_function ();
142
+ $ pdo_statement = $ this ->common_retrieval_function ();
145
143
146
144
if ( ! $ pdo_statement ) {
147
145
return false ;
@@ -157,7 +155,7 @@ public function first() {
157
155
* @return bool|PDOStatement
158
156
* @throws Exception
159
157
*/
160
- private function common_retrival_function () {
158
+ private function common_retrieval_function () {
161
159
if ( null === $ this ->tables ) {
162
160
throw new Exception ( 'Select: No table specified ' );
163
161
}
@@ -172,8 +170,8 @@ private function common_retrival_function() {
172
170
173
171
$ bindings = $ this ->where ['bindings ' ] ?? [];
174
172
175
- foreach ( $ bindings as $ key => $ value ) {
176
- $ pdo_statement ->bindValue ( $ key + 1 , $ value );
173
+ foreach ( $ bindings as $ key => $ binding ) {
174
+ $ pdo_statement ->bindValue ( $ key + 1 , $ binding );
177
175
}
178
176
179
177
$ result = $ pdo_statement ->execute ();
@@ -270,7 +268,8 @@ public function table( ...$args ) {
270
268
*/
271
269
public static function site_enabled ( $ site_name ) {
272
270
273
- $ site = self ::table ( 'sites ' )
271
+ $ db = new EE_DB ();
272
+ $ site = $ db ->table ( 'sites ' )
274
273
->select ( 'id ' , 'is_enabled ' )
275
274
->where ( 'sitename ' , $ site_name )
276
275
->first ();
@@ -292,10 +291,11 @@ public static function site_enabled( $site_name ) {
292
291
* @return string type of site.
293
292
*/
294
293
public static function get_site_command ( $ site_name ) {
295
- $ site = self ::table ( 'sites ' )
294
+ $ db = new EE_DB ();
295
+ $ site = $ db ->table ( 'sites ' )
296
296
->select ( 'site_command ' )
297
297
->where ( 'sitename ' , $ site_name )
298
- ->get ();
298
+ ->first ();
299
299
300
300
return $ site ['site_command ' ];
301
301
}
@@ -307,7 +307,7 @@ public static function get_site_command( $site_name ) {
307
307
* @throws Exception
308
308
*/
309
309
public function get () {
310
- $ pdo_statement = $ this ->common_retrival_function ();
310
+ $ pdo_statement = $ this ->common_retrieval_function ();
311
311
312
312
if ( ! $ pdo_statement ) {
313
313
return false ;
@@ -321,7 +321,8 @@ public function get() {
321
321
*/
322
322
public static function get_migrations () {
323
323
324
- $ migrations = self ::table ( 'migrations ' )
324
+ $ db = new EE_DB ();
325
+ $ migrations = $ db ->table ( 'migrations ' )
325
326
->select ( 'migration ' )
326
327
->get ();
327
328
@@ -372,7 +373,7 @@ public function insert( $data ) {
372
373
throw new Exception ( 'Insert: No table specified ' );
373
374
}
374
375
375
- if ( count ( $ this ->tables ) > 1 ) {
376
+ if ( strpos ( $ this ->tables , ' , ' ) !== false ) {
376
377
throw new Exception ( 'Insert: Multiple table specified ' );
377
378
}
378
379
@@ -412,7 +413,7 @@ public function update( $values ) {
412
413
throw new Exception ( 'Update: No where clause specified ' );
413
414
}
414
415
415
- if ( count ( $ this ->tables ) > 1 ) {
416
+ if ( strpos ( $ this ->tables , ' , ' ) !== false ) {
416
417
throw new Exception ( 'Update: Multiple table specified ' );
417
418
}
418
419
@@ -421,8 +422,8 @@ public function update( $values ) {
421
422
}
422
423
423
424
$ set_keys = array_keys ( $ values );
424
- $ set_values = array_values ( $ values );
425
- $ where_values = $ this ->where ['binding ' ];
425
+ $ set_bindings = array_values ( $ values );
426
+ $ where_bindings = $ this ->where ['bindings ' ];
426
427
427
428
$ set_clause = implode ( $ set_keys , ' = ?, ' ) . ' = ? ' ;
428
429
@@ -431,17 +432,17 @@ public function update( $values ) {
431
432
432
433
$ counter = 0 ; //We need counter here as we need to bind values of both SET and WHERE clauses
433
434
434
- foreach ( $ set_values as $ value ) {
435
- $ pdo_statement ->bindValue ( ++ $ counter , $ value );
435
+ foreach ( $ set_bindings as $ binding ) {
436
+ $ pdo_statement ->bindValue ( ++ $ counter , $ binding );
436
437
}
437
438
438
- foreach ( $ where_values as $ value ) {
439
- $ pdo_statement ->bindValue ( ++ $ counter , $ value );
439
+ foreach ( $ where_bindings as $ binding ) {
440
+ $ pdo_statement ->bindValue ( ++ $ counter , $ binding );
440
441
}
441
442
442
443
$ result = $ pdo_statement ->execute ();
443
444
444
- if ( ! $ query_exec ) {
445
+ if ( ! $ result ) {
445
446
EE ::debug ( self ::$ pdo ->errorInfo () );
446
447
447
448
return false ;
@@ -466,7 +467,7 @@ public function delete() {
466
467
throw new Exception ( 'Delete: No where clause specified ' );
467
468
}
468
469
469
- if ( count ( $ this ->tables ) > 1 ) {
470
+ if ( strpos ( $ this ->tables , ' , ' ) !== false ) {
470
471
throw new Exception ( 'Delete: Multiple table specified ' );
471
472
}
472
473
@@ -475,9 +476,11 @@ public function delete() {
475
476
$ pdo_statement = self ::$ pdo ->query ( $ query );
476
477
477
478
foreach ( $ this ->where ['bindings ' ] as $ key => $ binding ) {
478
- $ pdo_statement ->bindValue ( $ key + 1 , $ value );
479
+ $ pdo_statement ->bindValue ( $ key + 1 , $ binding );
479
480
}
480
481
482
+ $ result = $ pdo_statement ->execute ();
483
+
481
484
if ( ! $ result ) {
482
485
EE ::debug ( self ::$ pdo ->errorInfo () );
483
486
0 commit comments