@@ -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 |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | /** |
118 | 118 | * This method find a record by id |
119 | 119 | * @params int id |
120 | - * @return Object |
|
120 | + * @return BaseModel |
|
121 | 121 | * @throws NoArgumentPassedToFunctionException |
122 | 122 | */ |
123 | 123 | public static function find($id) |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | /** |
169 | 169 | * This method return the current class name |
170 | 170 | * $params void |
171 | - * @return classname |
|
171 | + * @return string|false |
|
172 | 172 | */ |
173 | 173 | public static function getClassName() |
174 | 174 | { |
@@ -20,150 +20,150 @@ discard block |
||
20 | 20 | |
21 | 21 | class BaseModel 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 |
|
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 | 26 | |
27 | - use Inflector; // Inject the inflector trait |
|
27 | + use Inflector; // Inject the inflector trait |
|
28 | 28 | |
29 | - public function __construct() |
|
30 | - { |
|
31 | - $this->tableName = $this->getClassName(); |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + $this->tableName = $this->getClassName(); |
|
32 | 32 | |
33 | - $this->databaseModel = new DatabaseHandler($this->tableName); |
|
33 | + $this->databaseModel = new DatabaseHandler($this->tableName); |
|
34 | 34 | |
35 | - $this->properties['id'] = 0; |
|
36 | - } |
|
35 | + $this->properties['id'] = 0; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * The magic getter method |
|
40 | - * @params key |
|
41 | - * @return array key |
|
42 | - */ |
|
43 | - public function __get($key) |
|
44 | - { |
|
45 | - $this->properties[$key]; |
|
46 | - |
|
47 | - } |
|
38 | + /** |
|
39 | + * The magic getter method |
|
40 | + * @params key |
|
41 | + * @return array key |
|
42 | + */ |
|
43 | + public function __get($key) |
|
44 | + { |
|
45 | + $this->properties[$key]; |
|
46 | + |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * The magic setter method |
|
51 | - * @params property, key |
|
52 | - * @return array associative array properties |
|
53 | - */ |
|
54 | - public function __set($property, $value) |
|
55 | - { |
|
56 | - $this->properties[$property] = $value; |
|
57 | - |
|
58 | - } |
|
49 | + /** |
|
50 | + * The magic setter method |
|
51 | + * @params property, key |
|
52 | + * @return array associative array properties |
|
53 | + */ |
|
54 | + public function __set($property, $value) |
|
55 | + { |
|
56 | + $this->properties[$property] = $value; |
|
57 | + |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * This method gets all the record from a particular table |
|
62 | - * @params void |
|
63 | - * @return associative array |
|
64 | - * @throws NoRecordFoundException |
|
65 | - */ |
|
66 | - public static function getAll() |
|
67 | - { |
|
68 | - $allData = DatabaseHandler::read($id = false, self::getClassName()); |
|
60 | + /** |
|
61 | + * This method gets all the record from a particular table |
|
62 | + * @params void |
|
63 | + * @return associative array |
|
64 | + * @throws NoRecordFoundException |
|
65 | + */ |
|
66 | + public static function getAll() |
|
67 | + { |
|
68 | + $allData = DatabaseHandler::read($id = false, self::getClassName()); |
|
69 | 69 | |
70 | - if (count($allData) > 0) { |
|
71 | - return $allData; |
|
70 | + if (count($allData) > 0) { |
|
71 | + return $allData; |
|
72 | 72 | |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - throw NoRecordFoundException::checkNoRecordFoundException("There is no record to display"); |
|
75 | + throw NoRecordFoundException::checkNoRecordFoundException("There is no record to display"); |
|
76 | 76 | |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * This method create or update record in a database table |
|
81 | - * @params void |
|
82 | - * @return bool true or false; |
|
83 | - * @throws EmptyArrayException |
|
84 | - * @throws NoRecordInsertionException |
|
85 | - * @throws NoRecordUpdateException |
|
86 | - */ |
|
87 | - public function save() |
|
88 | - { |
|
89 | - $boolCommit = false; |
|
90 | - |
|
91 | - if ($this->properties['id']) { |
|
92 | - $allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName()); |
|
93 | - |
|
94 | - if ($this->checkIfRecordIsEmpty($allData)) { |
|
95 | - $boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties); |
|
96 | - |
|
97 | - if ($boolCommit) { |
|
98 | - return true; |
|
99 | - |
|
100 | - } |
|
101 | - |
|
102 | - throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
103 | - } |
|
104 | - |
|
105 | - throw EmptyArrayException::checkEmptyArrayException("Value passed didn't match any record"); |
|
106 | - } |
|
107 | - |
|
108 | - $boolCommit = $this->databaseModel->create($this->properties, $this->tableName); |
|
109 | - |
|
110 | - if ($boolCommit) { |
|
111 | - return true; |
|
112 | - } |
|
113 | - |
|
114 | - throw NoRecordInsertionException::checkNoRecordAddedException("Record not created successfully"); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * This method find a record by id |
|
119 | - * @params int id |
|
120 | - * @return Object |
|
121 | - * @throws NoArgumentPassedToFunctionException |
|
122 | - */ |
|
123 | - public static function find($id) |
|
124 | - { |
|
125 | - $num_args = (int) func_num_args(); // get number of arguments passed to |
|
126 | - |
|
127 | - if ($num_args == 0 || $num_args > 1) { |
|
128 | - throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
129 | - } |
|
130 | - |
|
131 | - if ($id == "") { |
|
132 | - throw NullArgumentPassedToFunction::checkNullArgumentPassedToFunction("This function expect a value"); |
|
133 | - } |
|
134 | - |
|
135 | - $staticFindInstance = new static(); |
|
136 | - $staticFindInstance->id = $id == "" ? false : $id; |
|
137 | - |
|
138 | - return $staticFindInstance; |
|
79 | + /** |
|
80 | + * This method create or update record in a database table |
|
81 | + * @params void |
|
82 | + * @return bool true or false; |
|
83 | + * @throws EmptyArrayException |
|
84 | + * @throws NoRecordInsertionException |
|
85 | + * @throws NoRecordUpdateException |
|
86 | + */ |
|
87 | + public function save() |
|
88 | + { |
|
89 | + $boolCommit = false; |
|
90 | + |
|
91 | + if ($this->properties['id']) { |
|
92 | + $allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName()); |
|
93 | + |
|
94 | + if ($this->checkIfRecordIsEmpty($allData)) { |
|
95 | + $boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties); |
|
96 | + |
|
97 | + if ($boolCommit) { |
|
98 | + return true; |
|
99 | + |
|
100 | + } |
|
101 | + |
|
102 | + throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
103 | + } |
|
104 | + |
|
105 | + throw EmptyArrayException::checkEmptyArrayException("Value passed didn't match any record"); |
|
106 | + } |
|
107 | + |
|
108 | + $boolCommit = $this->databaseModel->create($this->properties, $this->tableName); |
|
109 | + |
|
110 | + if ($boolCommit) { |
|
111 | + return true; |
|
112 | + } |
|
113 | + |
|
114 | + throw NoRecordInsertionException::checkNoRecordAddedException("Record not created successfully"); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * This method find a record by id |
|
119 | + * @params int id |
|
120 | + * @return Object |
|
121 | + * @throws NoArgumentPassedToFunctionException |
|
122 | + */ |
|
123 | + public static function find($id) |
|
124 | + { |
|
125 | + $num_args = (int) func_num_args(); // get number of arguments passed to |
|
126 | + |
|
127 | + if ($num_args == 0 || $num_args > 1) { |
|
128 | + throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
129 | + } |
|
130 | + |
|
131 | + if ($id == "") { |
|
132 | + throw NullArgumentPassedToFunction::checkNullArgumentPassedToFunction("This function expect a value"); |
|
133 | + } |
|
134 | + |
|
135 | + $staticFindInstance = new static(); |
|
136 | + $staticFindInstance->id = $id == "" ? false : $id; |
|
137 | + |
|
138 | + return $staticFindInstance; |
|
139 | 139 | |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * This method delete a row from the table by the row id |
|
144 | - * @params int id |
|
145 | - * @return boolean true or false |
|
146 | - * @throws NoRecordDeletionException; |
|
147 | - */ |
|
148 | - public static function destroy($id) |
|
149 | - { |
|
150 | - $boolDeleted = false; |
|
151 | - |
|
152 | - $num_args = (int) func_num_args(); // get number of arguments passed to |
|
142 | + /** |
|
143 | + * This method delete a row from the table by the row id |
|
144 | + * @params int id |
|
145 | + * @return boolean true or false |
|
146 | + * @throws NoRecordDeletionException; |
|
147 | + */ |
|
148 | + public static function destroy($id) |
|
149 | + { |
|
150 | + $boolDeleted = false; |
|
151 | + |
|
152 | + $num_args = (int) func_num_args(); // get number of arguments passed to |
|
153 | 153 | |
154 | - if ($num_args == 0 || $num_args > 1) { |
|
155 | - throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
156 | - } |
|
154 | + if ($num_args == 0 || $num_args > 1) { |
|
155 | + throw NoArgumentPassedToFunctionException::checkNoArgumentPassedToFunction("Argument missing: only one argument is allowed"); |
|
156 | + } |
|
157 | 157 | |
158 | - $boolDeleted = DatabaseHandler::delete($id, self::getClassName()); |
|
158 | + $boolDeleted = DatabaseHandler::delete($id, self::getClassName()); |
|
159 | 159 | |
160 | - if ($boolDeleted) { |
|
161 | - return true; |
|
160 | + if ($boolDeleted) { |
|
161 | + return true; |
|
162 | 162 | |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | - throw NoRecordDeletionException::checkNoRecordUpdateException("Record deletion unsuccessful because id does not match any record"); |
|
166 | - } |
|
165 | + throw NoRecordDeletionException::checkNoRecordUpdateException("Record deletion unsuccessful because id does not match any record"); |
|
166 | + } |
|
167 | 167 | |
168 | 168 | /** |
169 | 169 | * This method return the current class name |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public static function getClassName() |
174 | 174 | { |
175 | - $tableName = preg_split('/(?=[A-Z])/', get_called_class()); |
|
175 | + $tableName = preg_split('/(?=[A-Z])/', get_called_class()); |
|
176 | 176 | |
177 | - $className = end($tableName); |
|
177 | + $className = end($tableName); |
|
178 | 178 | |
179 | - return self::pluralize(strtolower($className)); |
|
179 | + return self::pluralize(strtolower($className)); |
|
180 | 180 | |
181 | 181 | } |
182 | 182 | |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | * @param $arrayOfRecord |
186 | 186 | * @return bool |
187 | 187 | */ |
188 | - public function checkIfRecordIsEmpty($arrayOfRecord) |
|
189 | - { |
|
190 | - if (count($arrayOfRecord) > 0) { |
|
191 | - return true; |
|
188 | + public function checkIfRecordIsEmpty($arrayOfRecord) |
|
189 | + { |
|
190 | + if (count($arrayOfRecord) > 0) { |
|
191 | + return true; |
|
192 | 192 | |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - return false; |
|
196 | - } |
|
195 | + return false; |
|
196 | + } |
|
197 | 197 | |
198 | 198 | } |
@@ -9,7 +9,6 @@ |
||
9 | 9 | namespace Laztopaz\potatoORM; |
10 | 10 | |
11 | 11 | use PDO; |
12 | -use Laztopaz\potatoORM\DatabaseHelper; |
|
13 | 12 | use Laztopaz\potatoORM\TableFieldUndefinedException; |
14 | 13 | use Laztopaz\potatoORM\EmptyArrayException; |
15 | 14 |
@@ -21,6 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | /** |
23 | 23 | * This is a constructor; a default method that will be called automatically during class instantiation |
24 | + * @param string|false $modelClassName |
|
24 | 25 | */ |
25 | 26 | public function __construct($modelClassName, $dbConn = Null) |
26 | 27 | { |
@@ -35,6 +36,7 @@ discard block |
||
35 | 36 | /** |
36 | 37 | * This method create a record and store it in a table row |
37 | 38 | * @params associative array, string tablename |
39 | + * @param string|false $tableName |
|
38 | 40 | * @return boolean true or false |
39 | 41 | */ |
40 | 42 | public function create($associative1DArray, $tableName, $dbConn = Null) |
@@ -69,6 +71,7 @@ discard block |
||
69 | 71 | /** |
70 | 72 | * This method updates any table by supplying 3 parameter |
71 | 73 | * @params: $updateParams, $tableName, $associative1DArray |
74 | + * @param string|false $tableName |
|
72 | 75 | * @return boolean true or false |
73 | 76 | */ |
74 | 77 | public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null) |
@@ -101,6 +104,7 @@ discard block |
||
101 | 104 | /** |
102 | 105 | * This method retrieves record from a table |
103 | 106 | * @params int id, string tableName |
107 | + * @param string|false $tableName |
|
104 | 108 | * @return array |
105 | 109 | */ |
106 | 110 | public static function read($id, $tableName, $dbConn = Null) |
@@ -131,6 +135,7 @@ discard block |
||
131 | 135 | /** |
132 | 136 | * This method deletes a record from a table row |
133 | 137 | * @params int id, string tableName |
138 | + * @param string|false $tableName |
|
134 | 139 | * @return boolean true or false |
135 | 140 | */ |
136 | 141 | public static function delete($id, $tableName, $dbConn = Null) |
@@ -163,7 +168,7 @@ discard block |
||
163 | 168 | |
164 | 169 | /** |
165 | 170 | * This method returns sql query |
166 | - * @param $sql |
|
171 | + * @param string $sql |
|
167 | 172 | * @return string |
168 | 173 | */ |
169 | 174 | public function prepareUpdateQuery($sql) |
@@ -204,6 +209,7 @@ discard block |
||
204 | 209 | * This method returns column fields of a particular table |
205 | 210 | * @param $table |
206 | 211 | * @param $conn |
212 | + * @param DatabaseConnection $dbConn |
|
207 | 213 | * @return array |
208 | 214 | */ |
209 | 215 | public function getColumnNames($table, $dbConn = Null) { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
52 | 52 | |
53 | 53 | if (count($unexpectedFields) > 0) { |
54 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as a table field"); |
|
54 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as a table field"); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | unset($associative1DArray[0]); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | $insertQuery = 'INSERT INTO '.$tableName; |
78 | 78 | |
79 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
79 | + $TableValues = implode(',', array_keys($associative1DArray)); |
|
80 | 80 | |
81 | 81 | foreach ($associative1DArray as $field => $value) { |
82 | 82 | $FormValues[] = "'".trim(addslashes($value))."'"; |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | |
85 | 85 | $splittedTableValues = implode(',', $FormValues); |
86 | 86 | |
87 | - $insertQuery.= ' ('.$TableValues.')'; |
|
88 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
87 | + $insertQuery .= ' ('.$TableValues.')'; |
|
88 | + $insertQuery .= ' VALUES ('.$splittedTableValues.')'; |
|
89 | 89 | |
90 | 90 | $executeQuery = $dbConn->exec($insertQuery); |
91 | 91 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | $unexpectedFields = []; |
217 | 217 | |
218 | 218 | foreach ($userSetterArray as $key => $val) { |
219 | - if (!in_array($key,$tableColumn)) { |
|
219 | + if (!in_array($key, $tableColumn)) { |
|
220 | 220 | $unexpectedFields[] = $key; |
221 | 221 | } |
222 | 222 | } |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function prepareUpdateQuery($sql) |
234 | 234 | { |
235 | - $splittedQuery = explode(",",$sql); |
|
235 | + $splittedQuery = explode(",", $sql); |
|
236 | 236 | |
237 | 237 | array_pop($splittedQuery); |
238 | 238 | |
239 | - $mergeData = implode(",",$splittedQuery); |
|
239 | + $mergeData = implode(",", $splittedQuery); |
|
240 | 240 | |
241 | 241 | return $mergeData; |
242 | 242 |
@@ -18,133 +18,133 @@ discard block |
||
18 | 18 | |
19 | 19 | class DatabaseHandler { |
20 | 20 | |
21 | - private $tableFields; |
|
22 | - private $dbHelperInstance; |
|
23 | - private $dbConnection; |
|
24 | - private $model; |
|
21 | + private $tableFields; |
|
22 | + private $dbHelperInstance; |
|
23 | + private $dbConnection; |
|
24 | + private $model; |
|
25 | 25 | |
26 | - /** |
|
27 | - * This is a constructor; a default method that will be called automatically during class instantiation |
|
28 | - */ |
|
29 | - public function __construct($modelClassName, $dbConn = Null) |
|
30 | - { |
|
31 | - if (is_null($dbConn)) { |
|
32 | - $this->dbConnection = new DatabaseConnection(); |
|
33 | - |
|
34 | - } else { |
|
35 | - $this->dbConnection = $dbConn; |
|
36 | - |
|
37 | - } |
|
26 | + /** |
|
27 | + * This is a constructor; a default method that will be called automatically during class instantiation |
|
28 | + */ |
|
29 | + public function __construct($modelClassName, $dbConn = Null) |
|
30 | + { |
|
31 | + if (is_null($dbConn)) { |
|
32 | + $this->dbConnection = new DatabaseConnection(); |
|
33 | + |
|
34 | + } else { |
|
35 | + $this->dbConnection = $dbConn; |
|
36 | + |
|
37 | + } |
|
38 | 38 | |
39 | - $this->model = $modelClassName; |
|
40 | - } |
|
39 | + $this->model = $modelClassName; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * This method create a record and store it in a table row |
|
44 | - * @params associative array, string tablename |
|
45 | - * @return boolean true or false |
|
46 | - */ |
|
47 | - public function create($associative1DArray, $tableName, $dbConn = Null) |
|
48 | - { |
|
49 | - $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
|
50 | - |
|
51 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
|
42 | + /** |
|
43 | + * This method create a record and store it in a table row |
|
44 | + * @params associative array, string tablename |
|
45 | + * @return boolean true or false |
|
46 | + */ |
|
47 | + public function create($associative1DArray, $tableName, $dbConn = Null) |
|
48 | + { |
|
49 | + $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
|
50 | + |
|
51 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
|
52 | 52 | |
53 | - if (count($unexpectedFields) > 0) { |
|
54 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as a table field"); |
|
55 | - } |
|
53 | + if (count($unexpectedFields) > 0) { |
|
54 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as a table field"); |
|
55 | + } |
|
56 | 56 | |
57 | - unset($associative1DArray[0]); |
|
57 | + unset($associative1DArray[0]); |
|
58 | 58 | |
59 | - if (is_null($dbConn)) { |
|
60 | - $dbConn = $this->dbConnection; |
|
59 | + if (is_null($dbConn)) { |
|
60 | + $dbConn = $this->dbConnection; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - return $this->insertRecord($dbConn, $tableName, $associative1DArray); |
|
64 | + return $this->insertRecord($dbConn, $tableName, $associative1DArray); |
|
65 | 65 | |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * This method runs the insertion query |
|
70 | - * @param $dbConn |
|
71 | - * @param $tableName |
|
72 | - * @param $associative1DArray |
|
73 | - * @return boolean true |
|
74 | - */ |
|
75 | - private function insertRecord($dbConn, $tableName, $associative1DArray) |
|
76 | - { |
|
77 | - $insertQuery = 'INSERT INTO '.$tableName; |
|
68 | + /** |
|
69 | + * This method runs the insertion query |
|
70 | + * @param $dbConn |
|
71 | + * @param $tableName |
|
72 | + * @param $associative1DArray |
|
73 | + * @return boolean true |
|
74 | + */ |
|
75 | + private function insertRecord($dbConn, $tableName, $associative1DArray) |
|
76 | + { |
|
77 | + $insertQuery = 'INSERT INTO '.$tableName; |
|
78 | 78 | |
79 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
79 | + $TableValues = implode(',',array_keys($associative1DArray)); |
|
80 | 80 | |
81 | - foreach ($associative1DArray as $field => $value) { |
|
82 | - $FormValues[] = "'".trim(addslashes($value))."'"; |
|
83 | - } |
|
81 | + foreach ($associative1DArray as $field => $value) { |
|
82 | + $FormValues[] = "'".trim(addslashes($value))."'"; |
|
83 | + } |
|
84 | 84 | |
85 | - $splittedTableValues = implode(',', $FormValues); |
|
85 | + $splittedTableValues = implode(',', $FormValues); |
|
86 | 86 | |
87 | - $insertQuery.= ' ('.$TableValues.')'; |
|
88 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
87 | + $insertQuery.= ' ('.$TableValues.')'; |
|
88 | + $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
89 | 89 | |
90 | - $executeQuery = $dbConn->exec($insertQuery); |
|
90 | + $executeQuery = $dbConn->exec($insertQuery); |
|
91 | 91 | |
92 | - if ($executeQuery) { |
|
93 | - return true; |
|
94 | - } |
|
92 | + if ($executeQuery) { |
|
93 | + return true; |
|
94 | + } |
|
95 | 95 | |
96 | - return false; |
|
96 | + return false; |
|
97 | 97 | |
98 | - throw NoRecordInsertionException::checkNoRecordAddedException("Record not inserted successfully"); |
|
99 | - } |
|
98 | + throw NoRecordInsertionException::checkNoRecordAddedException("Record not inserted successfully"); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * This method updates any table by supplying 3 parameter |
|
103 | - * @params: $updateParams, $tableName, $associative1DArray |
|
104 | - * @return boolean true or false |
|
105 | - */ |
|
106 | - public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = null) |
|
107 | - { |
|
108 | - $sql = ""; |
|
101 | + /** |
|
102 | + * This method updates any table by supplying 3 parameter |
|
103 | + * @params: $updateParams, $tableName, $associative1DArray |
|
104 | + * @return boolean true or false |
|
105 | + */ |
|
106 | + public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = null) |
|
107 | + { |
|
108 | + $sql = ""; |
|
109 | 109 | |
110 | - if (is_null($dbConn)) { |
|
111 | - $dbConn = $this->dbConnection; |
|
110 | + if (is_null($dbConn)) { |
|
111 | + $dbConn = $this->dbConnection; |
|
112 | 112 | |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - $updateSql = "UPDATE `$tableName` SET "; |
|
115 | + $updateSql = "UPDATE `$tableName` SET "; |
|
116 | 116 | |
117 | - unset($associative1DArray['id']); |
|
117 | + unset($associative1DArray['id']); |
|
118 | 118 | |
119 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
119 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
120 | 120 | |
121 | - if (count($unexpectedFields) > 0) { |
|
122 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as a table field"); |
|
123 | - } |
|
121 | + if (count($unexpectedFields) > 0) { |
|
122 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as a table field"); |
|
123 | + } |
|
124 | 124 | |
125 | - foreach ($associative1DArray as $field => $value) { |
|
126 | - $sql .= "`$field` = '$value'".","; |
|
127 | - } |
|
125 | + foreach ($associative1DArray as $field => $value) { |
|
126 | + $sql .= "`$field` = '$value'".","; |
|
127 | + } |
|
128 | 128 | |
129 | - $updateSql .= $this->prepareUpdateQuery($sql); |
|
129 | + $updateSql .= $this->prepareUpdateQuery($sql); |
|
130 | 130 | |
131 | - foreach ($updateParams as $key => $val) { |
|
132 | - $updateSql .= " WHERE $key = $val"; |
|
133 | - } |
|
131 | + foreach ($updateParams as $key => $val) { |
|
132 | + $updateSql .= " WHERE $key = $val"; |
|
133 | + } |
|
134 | 134 | |
135 | - $stmt = $dbConn->prepare($updateSql); |
|
135 | + $stmt = $dbConn->prepare($updateSql); |
|
136 | 136 | |
137 | - $boolResponse = $stmt->execute(); |
|
137 | + $boolResponse = $stmt->execute(); |
|
138 | 138 | |
139 | - if ($boolResponse) { |
|
140 | - return true; |
|
139 | + if ($boolResponse) { |
|
140 | + return true; |
|
141 | 141 | |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | - return false; |
|
144 | + return false; |
|
145 | 145 | |
146 | - throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
147 | - } |
|
146 | + throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | /** |
150 | 150 | * This method retrieves record from a table |
@@ -153,26 +153,26 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public static function read($id, $tableName, $dbConn = null) |
155 | 155 | { |
156 | - $tableData = []; |
|
156 | + $tableData = []; |
|
157 | 157 | |
158 | - if (is_null($dbConn)) { |
|
159 | - $dbConn = new DatabaseConnection(); |
|
160 | - } |
|
158 | + if (is_null($dbConn)) { |
|
159 | + $dbConn = new DatabaseConnection(); |
|
160 | + } |
|
161 | 161 | |
162 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
162 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
163 | 163 | |
164 | - $stmt = $dbConn->prepare($sql); |
|
165 | - $stmt->bindValue(':table', $tableName); |
|
166 | - $stmt->bindValue(':id', $id); |
|
167 | - $stmt->execute(); |
|
164 | + $stmt = $dbConn->prepare($sql); |
|
165 | + $stmt->bindValue(':table', $tableName); |
|
166 | + $stmt->bindValue(':id', $id); |
|
167 | + $stmt->execute(); |
|
168 | 168 | |
169 | - $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
169 | + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
170 | 170 | |
171 | - foreach ($results as $result) { |
|
172 | - array_push($tableData, $result); |
|
173 | - } |
|
171 | + foreach ($results as $result) { |
|
172 | + array_push($tableData, $result); |
|
173 | + } |
|
174 | 174 | |
175 | - return $tableData; |
|
175 | + return $tableData; |
|
176 | 176 | |
177 | 177 | } |
178 | 178 | |
@@ -183,20 +183,20 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public static function delete($id, $tableName, $dbConn = null) |
185 | 185 | { |
186 | - if (is_null($dbConn)) { |
|
187 | - $dbConn = new DatabaseConnection(); |
|
188 | - } |
|
186 | + if (is_null($dbConn)) { |
|
187 | + $dbConn = new DatabaseConnection(); |
|
188 | + } |
|
189 | 189 | |
190 | - $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id; |
|
190 | + $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id; |
|
191 | 191 | |
192 | - $boolResponse = $dbConn->exec($sql); |
|
192 | + $boolResponse = $dbConn->exec($sql); |
|
193 | 193 | |
194 | - if ($boolResponse) { |
|
195 | - return true; |
|
194 | + if ($boolResponse) { |
|
195 | + return true; |
|
196 | 196 | |
197 | - } |
|
197 | + } |
|
198 | 198 | |
199 | - throw NoRecordDeletionException::checkNoRecordDeleteException("Record not deleted successfully"); |
|
199 | + throw NoRecordDeletionException::checkNoRecordDeleteException("Record not deleted successfully"); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public static function checkIfMagicSetterContainsIsSameAsClassModel(array $tableColumn, array $userSetterArray) |
209 | 209 | { |
210 | - $unexpectedFields = []; |
|
210 | + $unexpectedFields = []; |
|
211 | 211 | |
212 | - foreach ($userSetterArray as $key => $val) { |
|
213 | - if (!in_array($key,$tableColumn)) { |
|
214 | - $unexpectedFields[] = $key; |
|
215 | - } |
|
216 | - } |
|
212 | + foreach ($userSetterArray as $key => $val) { |
|
213 | + if (!in_array($key,$tableColumn)) { |
|
214 | + $unexpectedFields[] = $key; |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - return $unexpectedFields; |
|
218 | + return $unexpectedFields; |
|
219 | 219 | |
220 | 220 | } |
221 | 221 | |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function prepareUpdateQuery($sql) |
228 | 228 | { |
229 | - $splittedQuery = explode(",",$sql); |
|
229 | + $splittedQuery = explode(",",$sql); |
|
230 | 230 | |
231 | - array_pop($splittedQuery); |
|
231 | + array_pop($splittedQuery); |
|
232 | 232 | |
233 | - $mergeData = implode(",",$splittedQuery); |
|
233 | + $mergeData = implode(",",$splittedQuery); |
|
234 | 234 | |
235 | - return $mergeData; |
|
235 | + return $mergeData; |
|
236 | 236 | |
237 | 237 | } |
238 | 238 | |
@@ -245,27 +245,27 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function findAndWhere($params, $tableName, $dbConn = null) |
247 | 247 | { |
248 | - if (is_null($dbConn)) { |
|
249 | - $dbConn = $this->dbConnection; |
|
250 | - } |
|
248 | + if (is_null($dbConn)) { |
|
249 | + $dbConn = $this->dbConnection; |
|
250 | + } |
|
251 | 251 | |
252 | - if (is_array($params) && !empty($params)) { |
|
253 | - $sql = "SELECT * FROM ".$tableName; |
|
252 | + if (is_array($params) && !empty($params)) { |
|
253 | + $sql = "SELECT * FROM ".$tableName; |
|
254 | 254 | |
255 | - foreach ($params as $key => $val) { |
|
256 | - $sql .= " WHERE `$key` = '$val'"; |
|
257 | - } |
|
255 | + foreach ($params as $key => $val) { |
|
256 | + $sql .= " WHERE `$key` = '$val'"; |
|
257 | + } |
|
258 | 258 | |
259 | - $statement = $dbConn->prepare($sql); |
|
260 | - $statement->execute(); |
|
259 | + $statement = $dbConn->prepare($sql); |
|
260 | + $statement->execute(); |
|
261 | 261 | |
262 | - $returnedRowNumbers = $statement->rowCount(); |
|
262 | + $returnedRowNumbers = $statement->rowCount(); |
|
263 | 263 | |
264 | - return $returnedRowNumbers ? true : false; |
|
264 | + return $returnedRowNumbers ? true : false; |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - throw EmptyArrayException::checkEmptyArrayException("Record deletion unsuccessful because id does not match any record"); |
|
268 | + throw EmptyArrayException::checkEmptyArrayException("Record deletion unsuccessful because id does not match any record"); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -276,25 +276,25 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function getColumnNames($table, $dbConn = null) |
278 | 278 | { |
279 | - $tableFields = []; |
|
279 | + $tableFields = []; |
|
280 | 280 | |
281 | - if (is_null($dbConn)) { |
|
282 | - $dbConn = $this->dbConnection; |
|
283 | - } |
|
281 | + if (is_null($dbConn)) { |
|
282 | + $dbConn = $this->dbConnection; |
|
283 | + } |
|
284 | 284 | |
285 | - $sql = "SHOW COLUMNS FROM ".$table; |
|
285 | + $sql = "SHOW COLUMNS FROM ".$table; |
|
286 | 286 | |
287 | - $stmt = $dbConn->prepare($sql); |
|
288 | - $stmt->bindValue(':table', $table, PDO::PARAM_STR); |
|
289 | - $stmt->execute(); |
|
287 | + $stmt = $dbConn->prepare($sql); |
|
288 | + $stmt->bindValue(':table', $table, PDO::PARAM_STR); |
|
289 | + $stmt->execute(); |
|
290 | 290 | |
291 | - $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
291 | + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
292 | 292 | |
293 | - foreach ($results as $result) { |
|
294 | - array_push($tableFields, $result['Field']); |
|
295 | - } |
|
293 | + foreach ($results as $result) { |
|
294 | + array_push($tableFields, $result['Field']); |
|
295 | + } |
|
296 | 296 | |
297 | - return $tableFields; |
|
297 | + return $tableFields; |
|
298 | 298 | |
299 | 299 | } |
300 | 300 |
@@ -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 |
@@ -74,14 +74,14 @@ |
||
74 | 74 | 'sex' => 'sexes', |
75 | 75 | 'move' => 'moves'); |
76 | 76 | $lowercased_word = strtolower($word); |
77 | - foreach ($uncountable as $_uncountable){ |
|
78 | - if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){ |
|
77 | + foreach ($uncountable as $_uncountable) { |
|
78 | + if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) { |
|
79 | 79 | return $word; |
80 | 80 | } |
81 | 81 | } |
82 | - foreach ($irregular as $_plural=> $_singular){ |
|
82 | + foreach ($irregular as $_plural=> $_singular) { |
|
83 | 83 | if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
84 | - return preg_replace('/('.$_plural.')$/i', substr($arr[0],0,1).substr($_singular,1), $word); |
|
84 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | foreach ($plural as $rule => $replacement) { |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | class Inflector { |
12 | 12 | |
13 | - use Inflector; |
|
13 | + use Inflector; |
|
14 | 14 | } |
@@ -14,75 +14,75 @@ |
||
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 |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->loadEnv(); // load the environment variables |
|
26 | 26 | |
27 | - $this->databaseName = getenv('databaseName'); |
|
28 | - $this->databaseHost = getenv('databaseHost'); |
|
29 | - $this->databaseDriver = getenv('databaseDriver'); |
|
30 | - $this->databaseUsername = getenv('databaseUsername'); |
|
31 | - $this->databasePassword = getenv('databasePassword'); |
|
27 | + $this->databaseName = getenv('databaseName'); |
|
28 | + $this->databaseHost = getenv('databaseHost'); |
|
29 | + $this->databaseDriver = getenv('databaseDriver'); |
|
30 | + $this->databaseUsername = getenv('databaseUsername'); |
|
31 | + $this->databasePassword = getenv('databasePassword'); |
|
32 | 32 | |
33 | - try { |
|
34 | - $options = [ |
|
35 | - PDO::ATTR_PERSISTENT => true, |
|
36 | - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION |
|
37 | - ]; |
|
33 | + try { |
|
34 | + $options = [ |
|
35 | + PDO::ATTR_PERSISTENT => true, |
|
36 | + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION |
|
37 | + ]; |
|
38 | 38 | |
39 | - parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
|
39 | + parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
|
40 | 40 | |
41 | - } catch(PDOException $e) { |
|
42 | - return $e->getMessage(); |
|
41 | + } catch(PDOException $e) { |
|
42 | + return $e->getMessage(); |
|
43 | 43 | |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * This method determines the driver to be used for appropriate database server |
|
50 | - * @params void |
|
51 | - * @return string dsn |
|
52 | - */ |
|
53 | - public function getDatabaseDriver() |
|
54 | - { |
|
55 | - $dsn = ""; |
|
48 | + /** |
|
49 | + * This method determines the driver to be used for appropriate database server |
|
50 | + * @params void |
|
51 | + * @return string dsn |
|
52 | + */ |
|
53 | + public function getDatabaseDriver() |
|
54 | + { |
|
55 | + $dsn = ""; |
|
56 | 56 | |
57 | - switch ($this->databaseDriver) { |
|
58 | - case 'mysql': |
|
59 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; // Set DSN |
|
60 | - break; |
|
61 | - case 'sqlite': |
|
62 | - $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
63 | - break; |
|
64 | - case 'pgsql': |
|
65 | - $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
66 | - break; |
|
67 | - default: |
|
68 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
69 | - break; |
|
70 | - } |
|
57 | + switch ($this->databaseDriver) { |
|
58 | + case 'mysql': |
|
59 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; // Set DSN |
|
60 | + break; |
|
61 | + case 'sqlite': |
|
62 | + $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
63 | + break; |
|
64 | + case 'pgsql': |
|
65 | + $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
66 | + break; |
|
67 | + default: |
|
68 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
69 | + break; |
|
70 | + } |
|
71 | 71 | |
72 | - return $dsn; |
|
72 | + return $dsn; |
|
73 | 73 | |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Load Dotenv to grant getenv() access to environment variables in .env file |
|
78 | - */ |
|
79 | - public function loadEnv() |
|
80 | - { |
|
81 | - if (! getenv("APP_ENV")) { |
|
82 | - $dotenv = new Dotenv(__DIR__.'/../../'); |
|
83 | - $dotenv->load(); |
|
84 | - } |
|
76 | + /** |
|
77 | + * Load Dotenv to grant getenv() access to environment variables in .env file |
|
78 | + */ |
|
79 | + public function loadEnv() |
|
80 | + { |
|
81 | + if (! getenv("APP_ENV")) { |
|
82 | + $dotenv = new Dotenv(__DIR__.'/../../'); |
|
83 | + $dotenv->load(); |
|
84 | + } |
|
85 | 85 | |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | { |
25 | 25 | $this->loadEnv(); // load the environment variables |
26 | 26 | |
27 | - $this->databaseName = getenv('databaseName'); |
|
28 | - $this->databaseHost = getenv('databaseHost'); |
|
29 | - $this->databaseDriver = getenv('databaseDriver'); |
|
30 | - $this->databaseUsername = getenv('databaseUsername'); |
|
31 | - $this->databasePassword = getenv('databasePassword'); |
|
27 | + $this->databaseName = getenv('databaseName'); |
|
28 | + $this->databaseHost = getenv('databaseHost'); |
|
29 | + $this->databaseDriver = getenv('databaseDriver'); |
|
30 | + $this->databaseUsername = getenv('databaseUsername'); |
|
31 | + $this->databasePassword = getenv('databasePassword'); |
|
32 | 32 | |
33 | 33 | try { |
34 | 34 | $options = [ |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
40 | 40 | |
41 | - } catch(PDOException $e) { |
|
41 | + } catch (PDOException $e) { |
|
42 | 42 | return $e->getMessage(); |
43 | 43 | |
44 | 44 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function loadEnv() |
80 | 80 | { |
81 | - if (! getenv("APP_ENV")) { |
|
81 | + if (!getenv("APP_ENV")) { |
|
82 | 82 | $dotenv = new Dotenv(__DIR__.'/../../'); |
83 | 83 | $dotenv->load(); |
84 | 84 | } |
@@ -12,34 +12,34 @@ |
||
12 | 12 | |
13 | 13 | class DatabaseHelper { |
14 | 14 | |
15 | - public $dbConn; |
|
15 | + public $dbConn; |
|
16 | 16 | |
17 | - /** |
|
18 | - * This is a constructor; a default method that will be called automatically during class instantiation |
|
19 | - */ |
|
20 | - public function __construct($dbConnect) |
|
21 | - { |
|
22 | - $this->dbConn = $dbConnect; |
|
23 | - |
|
24 | - } |
|
17 | + /** |
|
18 | + * This is a constructor; a default method that will be called automatically during class instantiation |
|
19 | + */ |
|
20 | + public function __construct($dbConnect) |
|
21 | + { |
|
22 | + $this->dbConn = $dbConnect; |
|
23 | + |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * This method creates a particular table |
|
28 | - * @param tableName |
|
29 | - * $return boolean true or false |
|
30 | - */ |
|
31 | - public function createTable($tableName, $conn = NULL) |
|
32 | - { |
|
33 | - if (is_null($conn)) { |
|
34 | - $conn = $this->dbConn; |
|
35 | - } |
|
36 | - |
|
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 ) )'; |
|
39 | - |
|
40 | - return $conn->exec($sql); |
|
41 | - |
|
42 | - throw TableNotCreatedException::checkTableNotCreatedException("Check your database connection"); |
|
26 | + /** |
|
27 | + * This method creates a particular table |
|
28 | + * @param tableName |
|
29 | + * $return boolean true or false |
|
30 | + */ |
|
31 | + public function createTable($tableName, $conn = NULL) |
|
32 | + { |
|
33 | + if (is_null($conn)) { |
|
34 | + $conn = $this->dbConn; |
|
35 | + } |
|
36 | + |
|
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 ) )'; |
|
39 | + |
|
40 | + return $conn->exec($sql); |
|
41 | + |
|
42 | + throw TableNotCreatedException::checkTableNotCreatedException("Check your database connection"); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -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 |
@@ -12,10 +12,10 @@ |
||
12 | 12 | |
13 | 13 | class NullArgumentPassedToFunction extends Exception { |
14 | 14 | |
15 | - public static function checkNullArgumentPassedToFunction($message) |
|
16 | - { |
|
17 | - return new static ($message); |
|
15 | + public static function checkNullArgumentPassedToFunction($message) |
|
16 | + { |
|
17 | + return new static ($message); |
|
18 | 18 | |
19 | - } |
|
19 | + } |
|
20 | 20 | |
21 | 21 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | |
13 | 13 | class NoRecordFoundException extends Exception { |
14 | 14 | |
15 | - public static function checkNoRecordFoundException($message) |
|
16 | - { |
|
17 | - return new static($message); |
|
15 | + public static function checkNoRecordFoundException($message) |
|
16 | + { |
|
17 | + return new static($message); |
|
18 | 18 | |
19 | - } |
|
19 | + } |
|
20 | 20 | |
21 | 21 | } |