1 | <?php |
||
11 | class PotatoQuery |
||
12 | { |
||
13 | /** |
||
14 | * [$connection The connection to be used to communicate with the database. To be instantiated during construction.]. |
||
15 | * |
||
16 | * @var [type] PDO Connection. |
||
17 | */ |
||
18 | public $connection; |
||
19 | |||
20 | /** |
||
21 | * Setup the connection to aid all queries. |
||
22 | * |
||
23 | * @param PotatoConnector|null $connector [description] |
||
24 | */ |
||
25 | public function __construct(PotatoConnector $connector = null) |
||
30 | |||
31 | /** |
||
32 | * Get all records from the specified database table. |
||
33 | * |
||
34 | * @param string $table The table name |
||
35 | * @param string $columns The columns to be gotten from the database table |
||
36 | * |
||
37 | * @return array An array of objects, each representing a record fetched from the database table. |
||
38 | */ |
||
39 | public function getFrom($table, $columns = '*') |
||
50 | |||
51 | /** |
||
52 | * Get only one record from the datbase table, given the id of the record to be retrieved. |
||
53 | * |
||
54 | * @param string $table The database table name |
||
55 | * @param int $id The id of the recored to be fethced. |
||
56 | * |
||
57 | * @return model object The record fetched form the database table as an object |
||
58 | */ |
||
59 | public function getOne($table, $id) |
||
71 | |||
72 | /** |
||
73 | * Store a new recored inside athe database table. |
||
74 | * |
||
75 | * @param string $table The table into which it is required to add a new record |
||
76 | * @param string $data An aray of the columns to be used for inseting into the database |
||
77 | * |
||
78 | * @return bool The result of the query execution. True if successful. False otherwise. |
||
79 | */ |
||
80 | public function storeIn($table, $data) |
||
92 | |||
93 | /** |
||
94 | * Try executoing a query given the statment. |
||
95 | * |
||
96 | * @param PDOStatemetn $statement The PDO statment to be executed. |
||
97 | * |
||
98 | * @return bool The result of executing a query. True for success, false for failure |
||
99 | */ |
||
100 | public function tryExecuting($statement) |
||
111 | |||
112 | /** |
||
113 | * Throw an exception when there is a problem with execution of a statement. |
||
114 | * |
||
115 | * @param string $message The message to be related in the event of this exception |
||
116 | * |
||
117 | * @return [type] [description] |
||
118 | */ |
||
119 | public function throwFaultyExecutionException($message) |
||
123 | |||
124 | /** |
||
125 | * The columns to be inserted into the SQL query. |
||
126 | * |
||
127 | * @param array $data An array of the columns to be used for inserting int ot he database. |
||
128 | * |
||
129 | * @return string A string made up of the columns for insert query enclode in parentheses |
||
130 | */ |
||
131 | public function getColumns(array $data) |
||
135 | |||
136 | /** |
||
137 | * Bind parameters to the placeholders in the SQL queries. This is to avoid sql injection. |
||
138 | * |
||
139 | * @param [type] $statement The PDOStatement to be used to the binding. |
||
140 | * @param [array] $values The result of binding parameters to an SQL query. |
||
141 | */ |
||
142 | public function setBindForInsert($statement, $values) |
||
149 | |||
150 | /** |
||
151 | * Delete a record form a database table. |
||
152 | * |
||
153 | * @param [string] $table The table to be deleted from |
||
154 | * @param [int] $id the ID of the record to be deleted |
||
155 | * |
||
156 | * @return [type] The result of the deletion execution. |
||
157 | */ |
||
158 | public function deleteFrom($table, $id) |
||
168 | |||
169 | /** |
||
170 | * Update records in the datbase table. |
||
171 | * |
||
172 | * @param string $table The table who record ois to be updated |
||
173 | * @param [array] $data [The update data in an array] |
||
174 | * |
||
175 | * @return [bool] [The result of executing an SQL update query. TRUE OR FALSE] |
||
176 | */ |
||
177 | public function updateAt($table, $data) |
||
191 | |||
192 | /** |
||
193 | * Bind parameters to the placeholders in the SQL queries. This is to avoid sql injection. |
||
194 | * |
||
195 | * @param [type] $statement The PDOStatement to be used to the binding. |
||
196 | * @param [array] $values The result of binding parameters to an SQL query. |
||
197 | */ |
||
198 | public function setBindForUpdate($statement, array $data) |
||
205 | |||
206 | /** |
||
207 | * [makeModify Modify the query string to enable the binding for update. |
||
208 | * |
||
209 | * @param array $columns [The columns to be updated] |
||
210 | * |
||
211 | * @return [string] [The string of the columns to be updated and their corresponidng value_tags/ placeholders] E.g name = :name_val |
||
212 | */ |
||
213 | public function makeModify(array $columns) |
||
223 | |||
224 | /** |
||
225 | * [putQuesMarks Prepare a set of question-marks to comple an insert query SQL string. THis enables queryh binding. |
||
226 | * |
||
227 | * @param int $count The numbe rof column to be inserted |
||
228 | * |
||
229 | * @return string A string with the number of question marks needed for a complete insert query. E.g "?, ?" |
||
230 | */ |
||
231 | public function putQuesMarks($count) |
||
240 | |||
241 | /** |
||
242 | * [throwFaultyOrNoTableException Throw an exception if the table does not exist. |
||
243 | * |
||
244 | * @param string $table The table that foes not exist. |
||
245 | * |
||
246 | * @return [type] An exception with a custom message displayed when the databse table does not exist. |
||
247 | */ |
||
248 | public function throwFaultyOrNoTableException($table) |
||
253 | |||
254 | /** |
||
255 | * [throwNoRecordException Throw an Exception if there is no record found in the database table.] |
||
256 | * This may mean that the table is empty ot that the record with the given ID is not foung. |
||
257 | * |
||
258 | * @param [string] $table [The table that is empty or does not have the record with the given ID.] |
||
259 | * @param [int] $id [The ID of the record that does not exist in the databse table] |
||
260 | * |
||
261 | * @return [type] [description] |
||
262 | */ |
||
263 | public function throwNoRecordException($table, $id = null) |
||
268 | } |
||
269 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: