@@ -14,7 +14,6 @@ |
||
14 | 14 | use Laztopaz\potatoORM\NoRecordFoundException; |
15 | 15 | use Laztopaz\potatoORM\NoRecordInsertionException; |
16 | 16 | use Laztopaz\potatoORM\NullArgumentPassedToFunction; |
17 | -use Laztopaz\potatoORM\WrongArgumentException; |
|
18 | 17 | use Laztopaz\potatoORM\NoArgumentPassedToFunctionException; |
19 | 18 | use Laztopaz\potatoORM\EmptyArrayException; |
20 | 19 |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * This method find a record by id |
101 | 101 | * @params int id |
102 | - * @return Object |
|
102 | + * @return BaseClass |
|
103 | 103 | * @throws NoArgumentPassedToFunctionException |
104 | 104 | */ |
105 | 105 | public static function find($id) |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * This method return the current class name |
144 | 144 | * $params void |
145 | - * @return classname |
|
145 | + * @return string|false |
|
146 | 146 | */ |
147 | 147 | public static function getClassName() |
148 | 148 | { |
@@ -20,124 +20,124 @@ discard block |
||
20 | 20 | |
21 | 21 | class BaseClass implements InterfaceBaseClass |
22 | 22 | { |
23 | - protected $databaseModel; // Private variable that contains instance of database |
|
24 | - protected $tableName; // Class variable holding class name pluralized |
|
25 | - protected $properties = []; // Properties will later contain key, value pairs from the magic setter, getter methods |
|
26 | - use Inflector; // Inject the inflector trait |
|
23 | + protected $databaseModel; // Private variable that contains instance of database |
|
24 | + protected $tableName; // Class variable holding class name pluralized |
|
25 | + protected $properties = []; // Properties will later contain key, value pairs from the magic setter, getter methods |
|
26 | + use Inflector; // Inject the inflector trait |
|
27 | 27 | |
28 | - public function __construct() |
|
29 | - { |
|
30 | - $this->tableName = $this->getClassName(); |
|
31 | - $this->databaseModel = new DatabaseHandler($this->tableName); |
|
32 | - $this->properties['id'] = 0; |
|
33 | - } |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + $this->tableName = $this->getClassName(); |
|
31 | + $this->databaseModel = new DatabaseHandler($this->tableName); |
|
32 | + $this->properties['id'] = 0; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * The magic getter method |
|
37 | - * @params key |
|
38 | - * @return array key |
|
39 | - */ |
|
40 | - public function __get($key) |
|
41 | - { |
|
42 | - $this->properties[$key]; |
|
43 | - } |
|
35 | + /** |
|
36 | + * The magic getter method |
|
37 | + * @params key |
|
38 | + * @return array key |
|
39 | + */ |
|
40 | + public function __get($key) |
|
41 | + { |
|
42 | + $this->properties[$key]; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * The magic setter method |
|
47 | - * @params property, key |
|
48 | - * @return array associative array properties |
|
49 | - */ |
|
50 | - public function __set($property, $value) |
|
51 | - { |
|
52 | - $this->properties[$property] = $value; |
|
53 | - } |
|
45 | + /** |
|
46 | + * The magic setter method |
|
47 | + * @params property, key |
|
48 | + * @return array associative array properties |
|
49 | + */ |
|
50 | + public function __set($property, $value) |
|
51 | + { |
|
52 | + $this->properties[$property] = $value; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * This method gets all the record from a particular table |
|
57 | - * @params void |
|
58 | - * @return associative array |
|
59 | - * @throws NoRecordFoundException |
|
60 | - */ |
|
61 | - public static function getAll() |
|
62 | - { |
|
63 | - $allData = DatabaseHandler::read($id = false, self::getClassName()); |
|
64 | - if (count($allData) > 0) { |
|
65 | - return $allData; |
|
66 | - } |
|
67 | - throw NoRecordFoundException::checkNoRecordFoundException("There is no record to display"); |
|
68 | - } |
|
55 | + /** |
|
56 | + * This method gets all the record from a particular table |
|
57 | + * @params void |
|
58 | + * @return associative array |
|
59 | + * @throws NoRecordFoundException |
|
60 | + */ |
|
61 | + public static function getAll() |
|
62 | + { |
|
63 | + $allData = DatabaseHandler::read($id = false, self::getClassName()); |
|
64 | + if (count($allData) > 0) { |
|
65 | + return $allData; |
|
66 | + } |
|
67 | + throw NoRecordFoundException::checkNoRecordFoundException("There is no record to display"); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * This method create or update record in a database table |
|
72 | - * @params void |
|
73 | - * @return bool true or false; |
|
74 | - * @throws EmptyArrayException |
|
75 | - * @throws NoRecordInsertionException |
|
76 | - * @throws NoRecordUpdateException |
|
77 | - */ |
|
78 | - public function save() |
|
79 | - { |
|
80 | - $boolCommit = false; |
|
81 | - if ($this->properties['id']) { |
|
82 | - $allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName()); |
|
83 | - if ($this->checkIfRecordIsEmpty($allData)) { |
|
84 | - $boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties); |
|
85 | - if ($boolCommit) { |
|
86 | - return true; |
|
87 | - } |
|
88 | - throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
89 | - } |
|
90 | - throw EmptyArrayException::checkEmptyArrayException("Value passed didn't match any record"); |
|
91 | - } |
|
92 | - $boolCommit = $this->databaseModel->create($this->properties, $this->tableName); |
|
93 | - if ($boolCommit) { |
|
94 | - return true; |
|
95 | - } |
|
96 | - throw NoRecordInsertionException::checkNoRecordAddedException("Record not created successfully"); |
|
97 | - } |
|
70 | + /** |
|
71 | + * This method create or update record in a database table |
|
72 | + * @params void |
|
73 | + * @return bool true or false; |
|
74 | + * @throws EmptyArrayException |
|
75 | + * @throws NoRecordInsertionException |
|
76 | + * @throws NoRecordUpdateException |
|
77 | + */ |
|
78 | + public function save() |
|
79 | + { |
|
80 | + $boolCommit = false; |
|
81 | + if ($this->properties['id']) { |
|
82 | + $allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName()); |
|
83 | + if ($this->checkIfRecordIsEmpty($allData)) { |
|
84 | + $boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties); |
|
85 | + if ($boolCommit) { |
|
86 | + return true; |
|
87 | + } |
|
88 | + throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
89 | + } |
|
90 | + throw EmptyArrayException::checkEmptyArrayException("Value passed didn't match any record"); |
|
91 | + } |
|
92 | + $boolCommit = $this->databaseModel->create($this->properties, $this->tableName); |
|
93 | + if ($boolCommit) { |
|
94 | + return true; |
|
95 | + } |
|
96 | + throw NoRecordInsertionException::checkNoRecordAddedException("Record not created successfully"); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * This method find a record by id |
|
101 | - * @params int id |
|
102 | - * @return Object |
|
103 | - * @throws NoArgumentPassedToFunctionException |
|
104 | - */ |
|
105 | - public static function find($id) |
|
106 | - { |
|
107 | - $num_args = (int) func_num_args(); // get number of arguments passed to |
|
108 | - if ($num_args == 0 || $num_args > 1) { |
|
109 | - throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
110 | - } |
|
111 | - if ($id == "") { |
|
112 | - throw NullArgumentPassedToFunction::checkNullArgumentPassedToFunction("This function expect a value"); |
|
113 | - } |
|
114 | - $staticFindInstance = new static(); |
|
115 | - $staticFindInstance->id = $id == "" ? false : $id; |
|
116 | - return $staticFindInstance; |
|
99 | + /** |
|
100 | + * This method find a record by id |
|
101 | + * @params int id |
|
102 | + * @return Object |
|
103 | + * @throws NoArgumentPassedToFunctionException |
|
104 | + */ |
|
105 | + public static function find($id) |
|
106 | + { |
|
107 | + $num_args = (int) func_num_args(); // get number of arguments passed to |
|
108 | + if ($num_args == 0 || $num_args > 1) { |
|
109 | + throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
110 | + } |
|
111 | + if ($id == "") { |
|
112 | + throw NullArgumentPassedToFunction::checkNullArgumentPassedToFunction("This function expect a value"); |
|
113 | + } |
|
114 | + $staticFindInstance = new static(); |
|
115 | + $staticFindInstance->id = $id == "" ? false : $id; |
|
116 | + return $staticFindInstance; |
|
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * This method delete a row from the table by the row id |
|
122 | - * @params int id |
|
123 | - * @return boolean true or false |
|
124 | - * @throws NoRecordDeletionException; |
|
125 | - */ |
|
126 | - public static function destroy($id) |
|
127 | - { |
|
128 | - $boolDeleted = false; |
|
129 | - $num_args = (int) func_num_args(); // get number of arguments passed to |
|
120 | + /** |
|
121 | + * This method delete a row from the table by the row id |
|
122 | + * @params int id |
|
123 | + * @return boolean true or false |
|
124 | + * @throws NoRecordDeletionException; |
|
125 | + */ |
|
126 | + public static function destroy($id) |
|
127 | + { |
|
128 | + $boolDeleted = false; |
|
129 | + $num_args = (int) func_num_args(); // get number of arguments passed to |
|
130 | 130 | |
131 | - if ($num_args == 0 || $num_args > 1) { |
|
132 | - throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
133 | - } |
|
134 | - $boolDeleted = DatabaseHandler::delete($id, self::getClassName()); |
|
135 | - if ($boolDeleted) { |
|
136 | - return true; |
|
137 | - } |
|
138 | - throw NoRecordDeletionException::checkNoRecordUpdateException("Record deletion unsuccessful because id does not match any record"); |
|
131 | + if ($num_args == 0 || $num_args > 1) { |
|
132 | + throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
133 | + } |
|
134 | + $boolDeleted = DatabaseHandler::delete($id, self::getClassName()); |
|
135 | + if ($boolDeleted) { |
|
136 | + return true; |
|
137 | + } |
|
138 | + throw NoRecordDeletionException::checkNoRecordUpdateException("Record deletion unsuccessful because id does not match any record"); |
|
139 | 139 | |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | 142 | /** |
143 | 143 | * This method return the current class name |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | * @param $arrayOfRecord |
157 | 157 | * @return bool |
158 | 158 | */ |
159 | - public function checkIfRecordIsEmpty($arrayOfRecord) |
|
160 | - { |
|
161 | - if (count($arrayOfRecord) > 0) { |
|
162 | - return true; |
|
163 | - } |
|
164 | - return false; |
|
165 | - } |
|
159 | + public function checkIfRecordIsEmpty($arrayOfRecord) |
|
160 | + { |
|
161 | + if (count($arrayOfRecord) > 0) { |
|
162 | + return true; |
|
163 | + } |
|
164 | + return false; |
|
165 | + } |
|
166 | 166 | |
167 | 167 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | * @license <https://opensource.org/license/MIT> MIT |
7 | 7 | */ |
8 | 8 | |
9 | -namespace Laztopaz\potatoORM ; |
|
9 | +namespace Laztopaz\potatoORM; |
|
10 | 10 | |
11 | 11 | use Exception; |
12 | 12 |
@@ -12,8 +12,8 @@ |
||
12 | 12 | |
13 | 13 | class NoRecordInsertionException extends Exception { |
14 | 14 | |
15 | - public static function checkNoRecordAddedException($mesaage) |
|
16 | - { |
|
17 | - return new static($mesaage); |
|
18 | - } |
|
15 | + public static function checkNoRecordAddedException($mesaage) |
|
16 | + { |
|
17 | + return new static($mesaage); |
|
18 | + } |
|
19 | 19 | } |
@@ -8,7 +8,6 @@ |
||
8 | 8 | |
9 | 9 | namespace Laztopaz\potatoORM; |
10 | 10 | |
11 | -use PDO; |
|
12 | 11 | use Laztopaz\potatoORM\TableNotCreatedException; |
13 | 12 | |
14 | 13 | class DatabaseHelper { |
@@ -35,7 +35,7 @@ |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | $sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'('; |
38 | - $sql.= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )'; |
|
38 | + $sql .= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )'; |
|
39 | 39 | |
40 | 40 | return $conn->exec($sql); |
41 | 41 | throw TableNotCreatedException::tableNotCreatedException("Check your database connection"); |
@@ -13,25 +13,25 @@ |
||
13 | 13 | |
14 | 14 | class DatabaseHelper { |
15 | 15 | |
16 | - public $dbConn; |
|
16 | + public $dbConn; |
|
17 | 17 | |
18 | - /** |
|
19 | - * This is a constructor; a default method that will be called automatically during class instantiation |
|
20 | - */ |
|
21 | - public function __construct($dbConnect) |
|
22 | - { |
|
23 | - $this->dbConn = $dbConnect; |
|
24 | - } |
|
18 | + /** |
|
19 | + * This is a constructor; a default method that will be called automatically during class instantiation |
|
20 | + */ |
|
21 | + public function __construct($dbConnect) |
|
22 | + { |
|
23 | + $this->dbConn = $dbConnect; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * This method creates a particular table |
|
28 | - * @param tableName |
|
29 | - * $return boolean true or false |
|
30 | - */ |
|
26 | + /** |
|
27 | + * This method creates a particular table |
|
28 | + * @param tableName |
|
29 | + * $return boolean true or false |
|
30 | + */ |
|
31 | 31 | public function createTable($tableName, $conn = NULL) |
32 | 32 | { |
33 | 33 | if (is_null($conn)) { |
34 | - $conn = $this->dbConn; |
|
34 | + $conn = $this->dbConn; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | $sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'('; |
@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | class EmptyArrayException extends Exception { |
14 | 14 | |
15 | - public static function checkEmptyArrayException($message) |
|
16 | - { |
|
17 | - return new static($message); |
|
18 | - } |
|
15 | + public static function checkEmptyArrayException($message) |
|
16 | + { |
|
17 | + return new static($message); |
|
18 | + } |
|
19 | 19 | |
20 | 20 | } |
@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | class NoArgumentPassedToFunctionException extends Exception { |
14 | 14 | |
15 | - public static function checkNoArgumentPassedToFunction($message) |
|
16 | - { |
|
17 | - return new static($message); |
|
18 | - } |
|
15 | + public static function checkNoArgumentPassedToFunction($message) |
|
16 | + { |
|
17 | + return new static($message); |
|
18 | + } |
|
19 | 19 | |
20 | 20 | } |
@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | class NoRecordUpdateException extends Exception { |
14 | 14 | |
15 | - public static function checkNoRecordUpdateException($message) |
|
16 | - { |
|
17 | - return new static($message); |
|
18 | - } |
|
15 | + public static function checkNoRecordUpdateException($message) |
|
16 | + { |
|
17 | + return new static($message); |
|
18 | + } |
|
19 | 19 | |
20 | 20 | } |
@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | class WrongArgumentException extends Exception { |
14 | 14 | |
15 | - public function checkWrongArgumentException($message) |
|
16 | - { |
|
17 | - return new static ($message); |
|
18 | - } |
|
15 | + public function checkWrongArgumentException($message) |
|
16 | + { |
|
17 | + return new static ($message); |
|
18 | + } |
|
19 | 19 | |
20 | 20 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | public function __construct() |
24 | 24 | { |
25 | 25 | $this->loadEnv(); // load the environment variables |
26 | - $this->databaseName = getenv('databaseName'); |
|
27 | - $this->databaseHost = getenv('databaseHost'); |
|
28 | - $this->databaseDriver = getenv('databaseDriver'); |
|
29 | - $this->databaseUsername = getenv('databaseUsername'); |
|
30 | - $this->databasePassword = getenv('databasePassword'); |
|
26 | + $this->databaseName = getenv('databaseName'); |
|
27 | + $this->databaseHost = getenv('databaseHost'); |
|
28 | + $this->databaseDriver = getenv('databaseDriver'); |
|
29 | + $this->databaseUsername = getenv('databaseUsername'); |
|
30 | + $this->databasePassword = getenv('databasePassword'); |
|
31 | 31 | |
32 | 32 | try { |
33 | 33 | $options = [ |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | ]; |
37 | 37 | parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
38 | 38 | |
39 | - } catch(PDOException $e) { |
|
39 | + } catch (PDOException $e) { |
|
40 | 40 | return $e->getMessage(); |
41 | 41 | } |
42 | 42 | |
@@ -55,19 +55,19 @@ discard block |
||
55 | 55 | { |
56 | 56 | case 'mysql': |
57 | 57 | // Set DSN |
58 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
58 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
59 | 59 | break; |
60 | 60 | case 'sqlite': |
61 | 61 | // Set DSN |
62 | - $dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
62 | + $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
63 | 63 | break; |
64 | 64 | case 'pgsql': |
65 | 65 | // Set DSN |
66 | - $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
66 | + $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
67 | 67 | break; |
68 | 68 | default: |
69 | 69 | // Set DSN |
70 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
70 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
71 | 71 | } |
72 | 72 | return $dsn; |
73 | 73 | } |
@@ -14,73 +14,73 @@ |
||
14 | 14 | |
15 | 15 | class DatabaseConnection extends \PDO { |
16 | 16 | |
17 | - private $databaseName; |
|
18 | - private $databaseHost; |
|
19 | - private $databaseDriver; |
|
20 | - private $databaseUsername; |
|
21 | - private $databasePassword; |
|
17 | + private $databaseName; |
|
18 | + private $databaseHost; |
|
19 | + private $databaseDriver; |
|
20 | + private $databaseUsername; |
|
21 | + private $databasePassword; |
|
22 | 22 | |
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->loadEnv(); // load the environment variables |
|
26 | - $this->databaseName = getenv('databaseName'); |
|
27 | - $this->databaseHost = getenv('databaseHost'); |
|
28 | - $this->databaseDriver = getenv('databaseDriver'); |
|
29 | - $this->databaseUsername = getenv('databaseUsername'); |
|
30 | - $this->databasePassword = getenv('databasePassword'); |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->loadEnv(); // load the environment variables |
|
26 | + $this->databaseName = getenv('databaseName'); |
|
27 | + $this->databaseHost = getenv('databaseHost'); |
|
28 | + $this->databaseDriver = getenv('databaseDriver'); |
|
29 | + $this->databaseUsername = getenv('databaseUsername'); |
|
30 | + $this->databasePassword = getenv('databasePassword'); |
|
31 | 31 | |
32 | - try { |
|
33 | - $options = [ |
|
34 | - PDO::ATTR_PERSISTENT => true, |
|
35 | - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION |
|
36 | - ]; |
|
37 | - parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
|
32 | + try { |
|
33 | + $options = [ |
|
34 | + PDO::ATTR_PERSISTENT => true, |
|
35 | + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION |
|
36 | + ]; |
|
37 | + parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
|
38 | 38 | |
39 | - } catch(PDOException $e) { |
|
40 | - return $e->getMessage(); |
|
41 | - } |
|
39 | + } catch(PDOException $e) { |
|
40 | + return $e->getMessage(); |
|
41 | + } |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * This method determines the driver to be used for appropriate database server |
|
47 | - * @params void |
|
48 | - * @return string dsn |
|
49 | - */ |
|
50 | - public function getDatabaseDriver() |
|
51 | - { |
|
52 | - $dsn = ""; |
|
45 | + /** |
|
46 | + * This method determines the driver to be used for appropriate database server |
|
47 | + * @params void |
|
48 | + * @return string dsn |
|
49 | + */ |
|
50 | + public function getDatabaseDriver() |
|
51 | + { |
|
52 | + $dsn = ""; |
|
53 | 53 | |
54 | - switch ($this->databaseDriver) |
|
55 | - { |
|
56 | - case 'mysql': |
|
57 | - // Set DSN |
|
58 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
59 | - break; |
|
60 | - case 'sqlite': |
|
61 | - // Set DSN |
|
62 | - $dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
63 | - break; |
|
64 | - case 'pgsql': |
|
65 | - // Set DSN |
|
66 | - $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
67 | - break; |
|
68 | - default: |
|
69 | - // Set DSN |
|
70 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
71 | - } |
|
72 | - return $dsn; |
|
73 | - } |
|
54 | + switch ($this->databaseDriver) |
|
55 | + { |
|
56 | + case 'mysql': |
|
57 | + // Set DSN |
|
58 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
59 | + break; |
|
60 | + case 'sqlite': |
|
61 | + // Set DSN |
|
62 | + $dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
63 | + break; |
|
64 | + case 'pgsql': |
|
65 | + // Set DSN |
|
66 | + $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
67 | + break; |
|
68 | + default: |
|
69 | + // Set DSN |
|
70 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
71 | + } |
|
72 | + return $dsn; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Load Dotenv to grant getenv() access to environment variables in .env file |
|
77 | - */ |
|
78 | - public function loadEnv() |
|
79 | - { |
|
80 | - if (!getenv("APP_ENV")) { |
|
81 | - $dotenv = new Dotenv(__DIR__.'/../../'); |
|
82 | - $dotenv->load(); |
|
83 | - } |
|
84 | - } |
|
75 | + /** |
|
76 | + * Load Dotenv to grant getenv() access to environment variables in .env file |
|
77 | + */ |
|
78 | + public function loadEnv() |
|
79 | + { |
|
80 | + if (!getenv("APP_ENV")) { |
|
81 | + $dotenv = new Dotenv(__DIR__.'/../../'); |
|
82 | + $dotenv->load(); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | 86 | } |
@@ -10,12 +10,12 @@ |
||
10 | 10 | |
11 | 11 | interface InterfaceBaseClass { |
12 | 12 | |
13 | - /** |
|
14 | - * This method gets all the record from a particular table |
|
15 | - * @params void |
|
16 | - * @return associative array |
|
17 | - */ |
|
18 | - public static function getAll(); |
|
13 | + /** |
|
14 | + * This method gets all the record from a particular table |
|
15 | + * @params void |
|
16 | + * @return associative array |
|
17 | + */ |
|
18 | + public static function getAll(); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * This method create or update record in a database table |