1
1
<?php
2
2
3
3
/**
4
- * OpenDB - The lightweight PHP ORM
4
+ * StormQL - The lightweight PHP ORM
5
5
*
6
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
* of this software and associated documentation files (the "Software"), to deal
22
22
* SOFTWARE.
23
23
*
24
24
* @category Library
25
- * @package OpenDB
25
+ * @package StormQL
26
26
* @author Axel Nana <ax.lnana@outlook.com>
27
27
* @copyright 2018 Aliens Group, Inc.
28
28
* @license MIT <https://github.com/na2axl/bubble/blob/master/LICENSE>
29
29
* @version GIT: 0.0.1
30
30
* @link http://opengl.na2axl.tk
31
31
*/
32
32
33
- namespace OpenDB ;
33
+ namespace StormQL ;
34
34
35
35
/**
36
- * OpenDB - Database Manager Class
36
+ * StormQL - Database Manager Class
37
37
*
38
- * @package OpenDB
38
+ * @package StormQL
39
39
* @author Nana Axel <ax.lnana@outlook.com>
40
40
*/
41
- class OpenDB
41
+ class StormQL
42
42
{
43
43
/**
44
44
* Registered SQL operators.
@@ -373,9 +373,9 @@ public function getQueryString(): string
373
373
*
374
374
* @param string $table The table's name
375
375
*
376
- * @return OpenDB
376
+ * @return StormQL
377
377
*/
378
- public function from ($ table ): OpenDB
378
+ public function from ($ table ): StormQL
379
379
{
380
380
$ this ->table = $ table ;
381
381
return $ this ;
@@ -386,9 +386,9 @@ public function from($table): OpenDB
386
386
*
387
387
* @param string|array $condition
388
388
*
389
- * @return OpenDB
389
+ * @return StormQL
390
390
*/
391
- public function where ($ condition ): OpenDB
391
+ public function where ($ condition ): StormQL
392
392
{
393
393
// where(array('field1'=>'value', 'field2'=>'value'))
394
394
$ this ->where = (NULL !== $ this ->where ) ? "{$ this ->where } OR ( " : "( " ;
@@ -425,9 +425,9 @@ public function where($condition): OpenDB
425
425
* @param string $field
426
426
* @param string $mode
427
427
*
428
- * @return OpenDB
428
+ * @return StormQL
429
429
*/
430
- public function order ($ field , $ mode = "ASC " ): OpenDB
430
+ public function order ($ field , $ mode = "ASC " ): StormQL
431
431
{
432
432
$ this ->order = " ORDER BY {$ field } {$ mode } " ;
433
433
return $ this ;
@@ -439,9 +439,9 @@ public function order($field, $mode = "ASC"): OpenDB
439
439
* @param int $offset
440
440
* @param int $count
441
441
*
442
- * @return OpenDB
442
+ * @return StormQL
443
443
*/
444
- public function limit ($ offset , $ count ): OpenDB
444
+ public function limit ($ offset , $ count ): StormQL
445
445
{
446
446
$ this ->limit = " LIMIT {$ offset }, {$ count } " ;
447
447
return $ this ;
@@ -452,9 +452,9 @@ public function limit($offset, $count): OpenDB
452
452
*
453
453
* @param string $field The field used to group results
454
454
*
455
- * @return OpenDB
455
+ * @return StormQL
456
456
*/
457
- public function groupBy ($ field ): OpenDB
457
+ public function groupBy ($ field ): StormQL
458
458
{
459
459
$ this ->group = $ field ;
460
460
return $ this ;
@@ -463,9 +463,9 @@ public function groupBy($field): OpenDB
463
463
/**
464
464
* Add a distinct clause.
465
465
*
466
- * @return OpenDB
466
+ * @return StormQL
467
467
*/
468
- public function distinct (): OpenDB
468
+ public function distinct (): StormQL
469
469
{
470
470
$ this ->distinct = TRUE ;
471
471
return $ this ;
@@ -477,7 +477,7 @@ public function distinct(): OpenDB
477
477
* @param mixed $fields The fields to select. This value can be an array of fields,
478
478
* or a string of fields (according to the SELECT SQL query syntax).
479
479
*
480
- * @throws OpenDBException
480
+ * @throws StormQLException
481
481
*
482
482
* @return \PDOStatement
483
483
*/
@@ -492,7 +492,7 @@ public function select($fields = "*"): \PDOStatement
492
492
* @param mixed $fields The fields to select. This value can be an array of fields,
493
493
* or a string of fields (according to the SELECT SQL query syntax).
494
494
*
495
- * @throws OpenDBException
495
+ * @throws StormQLException
496
496
*
497
497
* @return \PDOStatement
498
498
*/
@@ -521,7 +521,7 @@ protected function _select($fields): \PDOStatement
521
521
$ this ->_reset_clauses ();
522
522
return $ getFieldsData ;
523
523
} else {
524
- throw new OpenDBException ($ getFieldsData ->errorInfo ()[2 ]);
524
+ throw new StormQLException ($ getFieldsData ->errorInfo ()[2 ]);
525
525
}
526
526
}
527
527
@@ -560,7 +560,7 @@ protected function _reset_clauses()
560
560
* @param mixed $fields The fields to select. This value can be an array of fields,
561
561
* or a string of fields (according to the SELECT SQL query syntax).
562
562
*
563
- * @throws OpenDBException
563
+ * @throws StormQLException
564
564
*
565
565
* @return array
566
566
*/
@@ -580,7 +580,7 @@ public function select_first($fields = "*"): array
580
580
* @param mixed $fields The fields to select. This value can be an array of fields,
581
581
* or a string of fields (according to the SELECT SQL query syntax).
582
582
*
583
- * @throws OpenDBException
583
+ * @throws StormQLException
584
584
*
585
585
* @return array
586
586
*/
@@ -602,7 +602,7 @@ public function select_array($fields = "*"): array
602
602
* @param mixed $fields The fields to select. This value can be an array of fields,
603
603
* or a string of fields (according to the SELECT SQL query syntax).
604
604
*
605
- * @throws OpenDBException
605
+ * @throws StormQLException
606
606
*
607
607
* @return array
608
608
*/
@@ -625,7 +625,7 @@ public function select_object($fields = "*"): array
625
625
* or a string of fields (according to the SELECT SQL query syntax).
626
626
* @param mixed $params The information used for jointures.
627
627
*
628
- * @throws OpenDBException
628
+ * @throws StormQLException
629
629
*
630
630
* @return \PDOStatement
631
631
*/
@@ -641,7 +641,7 @@ public function join($fields, $params): \PDOStatement
641
641
* or a string of fields (according to the SELECT SQL query syntax).
642
642
* @param string|array $params The information used for jointures.
643
643
*
644
- * @throws OpenDBException
644
+ * @throws StormQLException
645
645
*
646
646
* @return \PDOStatement
647
647
*/
@@ -667,7 +667,7 @@ private function _join($fields, $params): \PDOStatement
667
667
$ this ->_reset_clauses ();
668
668
return $ getFieldsData ;
669
669
} else {
670
- throw new OpenDBException ($ getFieldsData ->errorInfo ()[2 ]);
670
+ throw new StormQLException ($ getFieldsData ->errorInfo ()[2 ]);
671
671
}
672
672
}
673
673
@@ -678,7 +678,7 @@ private function _join($fields, $params): \PDOStatement
678
678
* or a string of fields (according to the SELECT SQL query syntax).
679
679
* @param mixed $params The information used for jointures.
680
680
*
681
- * @throws OpenDBException
681
+ * @throws StormQLException
682
682
*
683
683
* @return array
684
684
*/
@@ -701,7 +701,7 @@ public function join_array($fields, $params): array
701
701
* or a string of fields (according to the SELECT SQL query syntax).
702
702
* @param mixed $params The information used for jointures.
703
703
*
704
- * @throws OpenDBException
704
+ * @throws StormQLException
705
705
*
706
706
* @return array
707
707
*/
@@ -723,7 +723,7 @@ public function join_object($fields, $params): array
723
723
* @param string|array $fields The fields to select. This value can be an array of fields,
724
724
* or a string of fields (according to the SELECT SQL query syntax).
725
725
*
726
- * @throws OpenDBException
726
+ * @throws StormQLException
727
727
*
728
728
* @return int|array
729
729
*/
@@ -733,25 +733,25 @@ public function count($fields = "*")
733
733
$ field = implode (", " , $ fields );
734
734
}
735
735
736
- $ this ->queryString = "SELECT " . ((NULL !== $ this ->group ) ? "{$ this ->group }, " : " " ) . "COUNT( " . ((isset ($ field )) ? $ field : $ fields ) . ") AS opendb_count FROM {$ this ->table }" . ((NULL !== $ this ->where ) ? " WHERE {$ this ->where }" : " " ) . ((NULL !== $ this ->limit ) ? $ this ->limit : " " ) . ((NULL !== $ this ->group ) ? "GROUP BY {$ this ->group }" : " " );
736
+ $ this ->queryString = "SELECT " . ((NULL !== $ this ->group ) ? "{$ this ->group }, " : " " ) . "COUNT( " . ((isset ($ field )) ? $ field : $ fields ) . ") AS stormql_count FROM {$ this ->table }" . ((NULL !== $ this ->where ) ? " WHERE {$ this ->where }" : " " ) . ((NULL !== $ this ->limit ) ? $ this ->limit : " " ) . ((NULL !== $ this ->group ) ? "GROUP BY {$ this ->group }" : " " );
737
737
738
738
$ getFieldsData = $ this ->prepare ($ this ->queryString );
739
739
740
740
if ($ getFieldsData ->execute () !== FALSE ) {
741
741
if (NULL === $ this ->group ) {
742
742
$ this ->_reset_clauses ();
743
743
$ data = $ getFieldsData ->fetch ();
744
- return (int )$ data ['opendb_count ' ];
744
+ return (int )$ data ['stormql_count ' ];
745
745
}
746
746
747
747
$ this ->_reset_clauses ();
748
748
$ res = array ();
749
749
while ($ data = $ getFieldsData ->fetch ()) {
750
- $ res [$ data [$ this ->group ]] = $ data ['opendb_count ' ];
750
+ $ res [$ data [$ this ->group ]] = $ data ['stormql_count ' ];
751
751
}
752
752
return $ res ;
753
753
} else {
754
- throw new OpenDBException ($ getFieldsData ->errorInfo ()[2 ]);
754
+ throw new StormQLException ($ getFieldsData ->errorInfo ()[2 ]);
755
755
}
756
756
}
757
757
@@ -760,7 +760,7 @@ public function count($fields = "*")
760
760
*
761
761
* @param array $fieldsAndValues The fields and the associated values to insert.
762
762
*
763
- * @throws OpenDBException
763
+ * @throws StormQLException
764
764
*
765
765
* @return boolean
766
766
*/
@@ -785,7 +785,7 @@ public function insert($fieldsAndValues): bool
785
785
$ this ->_reset_clauses ();
786
786
return TRUE ;
787
787
} else {
788
- throw new OpenDBException ($ getFieldsData ->errorInfo ()[2 ]);
788
+ throw new StormQLException ($ getFieldsData ->errorInfo ()[2 ]);
789
789
}
790
790
}
791
791
@@ -794,7 +794,7 @@ public function insert($fieldsAndValues): bool
794
794
*
795
795
* @param array $fieldsAndValues The fields and the associated values to update.
796
796
*
797
- * @throws OpenDBException
797
+ * @throws StormQLException
798
798
*
799
799
* @return boolean
800
800
*/
@@ -821,14 +821,14 @@ public function update($fieldsAndValues): bool
821
821
$ this ->_reset_clauses ();
822
822
return TRUE ;
823
823
} else {
824
- throw new OpenDBException ($ getFieldsData ->errorInfo ()[2 ]);
824
+ throw new StormQLException ($ getFieldsData ->errorInfo ()[2 ]);
825
825
}
826
826
}
827
827
828
828
/**
829
829
* Deletes data in table.
830
830
*
831
- * @throws OpenDBException
831
+ * @throws StormQLException
832
832
*
833
833
* @return boolean
834
834
*/
@@ -842,7 +842,7 @@ public function delete(): bool
842
842
$ this ->_reset_clauses ();
843
843
return TRUE ;
844
844
} else {
845
- throw new OpenDBException ($ getFieldsData ->errorInfo ()[2 ]);
845
+ throw new StormQLException ($ getFieldsData ->errorInfo ()[2 ]);
846
846
}
847
847
}
848
848
@@ -879,6 +879,6 @@ public function quote($value): string
879
879
/**
880
880
* Dummy class used to throw exceptions
881
881
*/
882
- class OpenDBException extends \Exception
882
+ class StormQLException extends \Exception
883
883
{
884
884
}
0 commit comments