-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathezsqlModelInterface.php
More file actions
468 lines (443 loc) · 17.5 KB
/
ezsqlModelInterface.php
File metadata and controls
468 lines (443 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<?php
namespace ezsql;
/**
* @method void setDebugAll($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setTrace($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setDebugCalled($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setVarDumpCalled($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setShowErrors($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setNumQueries($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setConnQueries($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setCapturedErrors($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setCacheDir($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setUseDiskCache($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setCacheTimeout($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setCacheQueries($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setCacheInserts($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setNumRows($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setDbConnectTime($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setSqlLogFile($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setProfileTimes($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setInsertId($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setLastQuery($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setLastError($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setColInfo($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setTimers($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setTotalQueryTime($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setTraceLog($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setUseTraceLog($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setDoProfile($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setLastResult($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setFromDiskCache($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setDebugEchoIsOn($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setFuncCall($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setAllFuncCalls($args);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setTable($name);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method void setPrefix($append);
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
*
* @method string getDebugAll();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getTrace();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getDebugCalled();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getVarDumpCalled();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getShowErrors();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getNumQueries();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getConnQueries();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getCapturedErrors();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getCacheDir();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getUseDiskCache();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getCacheTimeout();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getCacheQueries();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getCacheInserts();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getNumRows();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getDbConnectTime();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getSqlLogFile();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getProfileTimes();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getInsertId();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getLastQuery();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getLastError();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getColInfo();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getTimers();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getTotalQueryTime();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getTraceLog();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getUseTraceLog();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getDoProfile();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getLastResult();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getFromDiskCache();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getDebugEchoIsOn();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getFuncCall();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getAllFuncCalls();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getTable();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
* @method string getPrefix();
* A `ezsqlModel` class property that can be accessed with either
* a `set` or `get` prefix as a function.
*/
interface ezsqlModelInterface
{
/**
* Get host and port from an "host:port" notation.
*
* @param string $host
* @param bool $default
* @return array of host and port. If port is omitted, returns $default
*/
public function get_host_port(string $host, bool $default = false);
/**
* Store Query/SQL/DB error - over-ridden by specific DB class
*
* @param string $err_str
* @param bool $displayError
* @return bool
* @throws Exception
*/
public function register_error(string $err_str, bool $displayError = true);
/**
* Turn error output to browser on.
*
* - If you have not used the function `$db->hide_errors()` this function (show_errors)
* will have no effect.
*/
public function show_errors();
/**
* Turn error output to browser off.
*
* Stops error output from being printed to the web client.
* - If you would like to stop error output but still be able to trap errors for debugging
* or for your own error output function you can make use of the global error array $captured_errors. access by calling `$db->getCaptured_Errors()`
*/
public function hide_errors();
/**
* Kill cached query results
*/
public function flush();
/**
* Log how the query function was called
*
* @param string $query
*/
public function log_query(string $query);
/**
* Get one variable, from one row, from the database (or previously cached results).
*
* This function is very useful for evaluating query results within logic statements such as if or switch.
* - If the query generates more than one row the first row will always be used by default.
* - If the query generates more than one column the leftmost column will always be used by default.
* - Even so, the full results set will be available within the
* array `$db->last_results` should you wish to use them.
*
* @param string $query
* @param int $x - column offset
* @param int $y - row offset
* @return bool|mixed
*/
public function get_var(?string $query = null, int $x = 0, int $y = 0, bool $use_prepare = false);
/**
* Get one row from the database (or previously cached results)
*
* - If the query returns more than one row and no row offset is
* supplied the first row within the results set will be returned by
* default.
* - Even so, the full results will be cached should you wish
* to use them with another ezSQL query.
*
* @param string $query
* @param OBJECT|ARRAY_A|ARRAY_N $output
* @param int $y - row offset
* @return bool|mixed
*/
public function get_row(?string $query = null, $output = \OBJECT, int $y = 0, bool $use_prepare = false);
/**
* Get one column from query (or previously cached results) based on column offset
*
* Extracts one column as one dimensional array based on a column
* offset.
* - If no offset is supplied the offset will default to column 0. I.E the first column.
* - If a null query is supplied the previous query results are used.
*
* @param string $query
* @param int $x - column offset
* @param bool $use_prepare - has prepare statements been activated
* @return bool|mixed
*/
public function get_col(?string $query = null, int $x = 0, bool $use_prepare = false);
/**
* Get multiple row result set from the database
* (or previously cached results), based on query and returns them as
* a multi dimensional array.
*
* Each element of the array contains one row of results and can be
* specified to be either an object, associative array or numerical
* array.
* - If no results are found then the function returns `false`,
* enabling you to use the function within logic statements such as if.
*
* - if setup/active, `prepareActive()` has been called, use
* prepare statements in SQL transactions.
*
* **OBJECT** - `Returning results as an object` is the quickest way to get and
* display results. It is also useful that you are able to put
* `$object->var` syntax directly inside print statements without
* having to worry about causing php parsing errors.
*
* **ARRAY_A** - `Returning results as an associative array` is useful if you would
* like dynamic access to column names.
*
* **ARRAY_N** - `Returning results as a numerical array` is useful if you are using
* completely dynamic queries with varying column names but still need
* a way to get a handle on the results.
*
* **JSON** - `Returning results as JSON encoded` is useful for any interactive dynamic queries.
* @param string $query
* @param constant $output Either: `OBJECT`|`ARRAY_A`|`ARRAY_N`|`JSON`
* @param bool $use_prepare - has prepare statements been activated
* @return bool|object|array - results as objects (default)
*/
public function get_results(?string $query = null, $output = \OBJECT, bool $use_prepare = false);
/**
* Get information about one or all columns such as column name or type.
*
* Returns meta information about one or all columns such as column name or type.
* - If no information type is supplied then the default information type of name is used.
* - If no column offset is supplied then a one dimensional array is returned with the
* information type for all columns.
* - For access to the full meta information for all columns you can use the cached
* variable `$db->colInfo`, access by calling `$db->getCol_Info()`
*
* Available Info-Types:
* mySQL
* - name - column name
* - table - name of the table the column belongs to
* - max_length - maximum length of the column
* - not_null - 1 if the column cannot be NULL
* - primary_key - 1 if the column is a primary key
* - unique_key - 1 if the column is a unique key
* - multiple_key - 1 if the column is a non-unique key
* - numeric - 1 if the column is numeric
* - blob - 1 if the column is a BLOB
* - type - the type of the column
* - unsigned - 1 if the column is unsigned
* - zerofill - 1 if the column is zero-filled
*
* MS-SQL / Oracle / PostgresSQL
* - name - column name
* - type - the type of the column
* - length - size of column
*
* SQLite
* - name - column name
*
* @param string $info_type
* @param int $col_offset
* @return mixed
*/
public function get_col_info(string $info_type = "name", int $col_offset = -1);
/**
* create cache directory if doesn't exists
*
* @param string $path
*/
public function create_cache(?string $path = null);
/**
* Store cache
*
* @param string $query
* @param bool $is_insert
*/
public function store_cache(string $query, bool $is_insert);
/**
* Get stored cache
*
* @param string $query
* @return mixed
*/
public function get_cache(string $query);
/**
* Dumps the contents of any input variable to screen in a nicely
* formatted and easy to understand way.
*
* @param mixed $mixed- any type Object, public or Array
* @return string|void
*/
public function varDump($mixed = null);
/**
* @internal alias for varDump()
*/
public function dump_var($mixed = null);
/**
* Displays the last sql query and returned results (if any)
*
* @param boolean $print_to_screen
* @return string
*/
public function debug($print_to_screen = true);
/**
* Timer related functions
*/
public function timer_get_cur();
public function timer_start($timer_name);
public function timer_elapsed($timer_name);
public function timer_update_global($timer_name);
/**
* Function for operating query count
*
* @param bool $all Set to false for function to return queries only during this connection
* @param bool $increase Set to true to increase query count (internal usage)
* @return int Returns query count base on $all
*/
public function count($all = true, $increase = false);
/**
* Returns `true` if the database connection is established.
*
* @return bool
*/
public function isConnected();
/**
* Returns the `number` of affected rows of a query.
*
* @return int
*/
public function affectedRows();
/**
* Returns the last query `result`.
*
* @return object
*/
public function queryResult();
/**
* Setup table `name` and `prefix` for global usage on calls to database **method/function** *names* ending with `ing`.
*
* @param string $name
* @param string $prefix
* @return void
*/
public function tableSetup(string $name = '', string $prefix = '');
}