1 | <?php |
||
19 | abstract class Give_DB { |
||
20 | |||
21 | /** |
||
22 | * The name of our database table |
||
23 | * |
||
24 | * @access public |
||
25 | * @since 1.0 |
||
26 | */ |
||
27 | public $table_name; |
||
28 | |||
29 | /** |
||
30 | * The version of our database table |
||
31 | * |
||
32 | * @access public |
||
33 | * @since 1.0 |
||
34 | */ |
||
35 | public $version; |
||
36 | |||
37 | /** |
||
38 | * The name of the primary column |
||
39 | * |
||
40 | * @access public |
||
41 | * @since 1.0 |
||
42 | */ |
||
43 | public $primary_key; |
||
44 | |||
45 | /** |
||
46 | * Get things started |
||
47 | * |
||
48 | * @access public |
||
49 | * @since 1.0 |
||
50 | */ |
||
51 | public function __construct() { |
||
53 | |||
54 | /** |
||
55 | * Whitelist of columns |
||
56 | * |
||
57 | * @access public |
||
58 | * @since 1.0 |
||
59 | * @return array |
||
60 | */ |
||
61 | public function get_columns() { |
||
64 | |||
65 | /** |
||
66 | * Default column values |
||
67 | * |
||
68 | * @access public |
||
69 | * @since 1.0 |
||
70 | * @return array |
||
71 | */ |
||
72 | public function get_column_defaults() { |
||
75 | |||
76 | /** |
||
77 | * Retrieve a row by the primary key |
||
78 | * |
||
79 | * @access public |
||
80 | * @since 1.0 |
||
81 | * @return object |
||
82 | */ |
||
83 | public function get( $row_id ) { |
||
88 | |||
89 | /** |
||
90 | * Retrieve a row by a specific column / value |
||
91 | * |
||
92 | * @access public |
||
93 | * @since 1.0 |
||
94 | * @return object |
||
95 | */ |
||
96 | public function get_by( $column, $row_id ) { |
||
101 | |||
102 | /** |
||
103 | * Retrieve a specific column's value by the primary key |
||
104 | * |
||
105 | * @access public |
||
106 | * @since 1.0 |
||
107 | * @return string |
||
108 | */ |
||
109 | 34 | public function get_column( $column, $row_id ) { |
|
114 | |||
115 | /** |
||
116 | * Retrieve a specific column's value by the the specified column / value |
||
117 | * |
||
118 | * @access public |
||
119 | * @since 1.0 |
||
120 | * @return string |
||
121 | */ |
||
122 | 2 | public function get_column_by( $column, $column_where, $column_value ) { |
|
127 | |||
128 | /** |
||
129 | * Insert a new row |
||
130 | * |
||
131 | * @access public |
||
132 | * @since 1.0 |
||
133 | * @return int |
||
134 | */ |
||
135 | 34 | public function insert( $data, $type = '' ) { |
|
162 | |||
163 | /** |
||
164 | * Update a row |
||
165 | * |
||
166 | * @access public |
||
167 | * @since 1.0 |
||
168 | * @return bool |
||
169 | */ |
||
170 | 34 | public function update( $row_id, $data = array(), $where = '' ) { |
|
204 | |||
205 | /** |
||
206 | * Delete a row identified by the primary key |
||
207 | * |
||
208 | * @access public |
||
209 | * @since 1.0 |
||
210 | * @return bool |
||
211 | */ |
||
212 | public function delete( $row_id = 0 ) { |
||
229 | |||
230 | /** |
||
231 | * Check if the given table exists |
||
232 | * |
||
233 | * @since 1.3.2 |
||
234 | * @param string $table The table name |
||
235 | * @return bool If the table name exists |
||
236 | */ |
||
237 | 2 | public function table_exists( $table ) { |
|
243 | |||
244 | } |
||
245 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.