1 | <?php |
||
18 | class Query |
||
19 | { |
||
20 | /** |
||
21 | * |
||
22 | */ |
||
23 | const TYPE_QUERY = 'QUERY'; |
||
24 | /** |
||
25 | * |
||
26 | */ |
||
27 | const TYPE_SELECT = 'SELECT'; |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | */ |
||
32 | const TYPE_INSERT = 'INSERT'; |
||
33 | |||
34 | /** |
||
35 | * |
||
36 | */ |
||
37 | const TYPE_UPDATE = 'UPDATE'; |
||
38 | |||
39 | /** |
||
40 | * |
||
41 | */ |
||
42 | const TYPE_DELETE = 'DELETE'; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | public $table; |
||
48 | |||
49 | /** |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $attributes = array( |
||
53 | 'where' => array(), |
||
54 | 'columns' => array() |
||
55 | ); |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $type = "SELECT"; |
||
61 | |||
62 | /** |
||
63 | * @param null $table |
||
64 | */ |
||
65 | 45 | public function __construct($table = null) |
|
69 | |||
70 | /** |
||
71 | * @param $queryStr |
||
72 | * @param $params |
||
73 | * @return Query |
||
74 | */ |
||
75 | 45 | public static function sql($queryStr, $params = null) |
|
85 | |||
86 | /** |
||
87 | * @param $table |
||
88 | * @return Query |
||
89 | */ |
||
90 | 3 | public static function table($table) |
|
94 | |||
95 | /** |
||
96 | * @param $table |
||
97 | */ |
||
98 | public function setTable($table) |
||
102 | |||
103 | /** |
||
104 | * @param $columns |
||
105 | * @return $this |
||
106 | */ |
||
107 | 3 | public function select($columns = null) |
|
113 | |||
114 | /** |
||
115 | * @param array $columnsVal |
||
116 | * @return $this |
||
117 | */ |
||
118 | 3 | public function insert(array $columnsVal) |
|
125 | |||
126 | |||
127 | /** |
||
128 | * @param $columnsVal |
||
129 | * @return $this |
||
130 | */ |
||
131 | 3 | public function update($columnsVal) |
|
138 | |||
139 | /** |
||
140 | * @return $this |
||
141 | */ |
||
142 | 3 | public function delete() |
|
147 | |||
148 | /** |
||
149 | * @param $query |
||
150 | * @param string $type |
||
151 | * @return Query |
||
152 | */ |
||
153 | 3 | public function whereQ(Query $query, $type = "AND") |
|
160 | |||
161 | /** |
||
162 | * @param $column |
||
163 | * @param $value |
||
164 | * @param string $operator |
||
165 | * @param string $type |
||
166 | * @return Query |
||
167 | */ |
||
168 | 3 | public function where($column, $value, $operator = "=", $type = "AND") |
|
173 | |||
174 | /** |
||
175 | * @param $column |
||
176 | * @param $value |
||
177 | * @param string $operator |
||
178 | * @return Query |
||
179 | */ |
||
180 | 3 | public function andWhere($column, $value, $operator = "=") |
|
184 | |||
185 | /** |
||
186 | * @param $column |
||
187 | * @param $value |
||
188 | * @param string $operator |
||
189 | * @return Query |
||
190 | */ |
||
191 | 3 | public function orWhere($column, $value, $operator = "=") |
|
195 | |||
196 | /** |
||
197 | * @param $column |
||
198 | * @param $value |
||
199 | * @param string $type |
||
200 | * @return Query |
||
201 | */ |
||
202 | 3 | public function like($column, $value, $type = "AND") |
|
206 | |||
207 | /** |
||
208 | * @param $column |
||
209 | * @param $value |
||
210 | * @return Query |
||
211 | */ |
||
212 | 3 | public function andLike($column, $value) |
|
216 | |||
217 | /** |
||
218 | * @param $column |
||
219 | * @param $value |
||
220 | * @return Query |
||
221 | */ |
||
222 | 3 | public function orLike($column, $value) |
|
226 | |||
227 | /** |
||
228 | * @param $column |
||
229 | * @param array $value |
||
230 | * @param string $type |
||
231 | * @return Query |
||
232 | */ |
||
233 | public function between($column, $value = array(), $type = "AND") |
||
241 | |||
242 | /** |
||
243 | * @param $column |
||
244 | * @param array $value |
||
245 | * @return Query |
||
246 | */ |
||
247 | public function andBetween($column, $value = array()) |
||
251 | |||
252 | /** |
||
253 | * @param $column |
||
254 | * @param $value |
||
255 | * @return Query |
||
256 | */ |
||
257 | public function orBetween($column, $value) |
||
261 | |||
262 | /** |
||
263 | * @param $column |
||
264 | * @param $order |
||
265 | * @return $this |
||
266 | */ |
||
267 | 3 | public function sort($column, $order) |
|
276 | |||
277 | /** |
||
278 | * @param $column |
||
279 | * @return Query |
||
280 | */ |
||
281 | 3 | public function asc($column) |
|
285 | |||
286 | /** |
||
287 | * @param $column |
||
288 | * @return Query |
||
289 | */ |
||
290 | 3 | public function desc($column) |
|
294 | |||
295 | /** |
||
296 | * @param $num |
||
297 | * @param null $offset |
||
298 | * @return $this |
||
299 | */ |
||
300 | 3 | public function limit($num, $offset = null) |
|
307 | |||
308 | /** |
||
309 | * @param Grammar $grammar |
||
310 | * @return array |
||
311 | */ |
||
312 | 60 | public function build(Grammar $grammar) |
|
324 | |||
325 | /** |
||
326 | * Clear Query Builder |
||
327 | */ |
||
328 | public function clear() |
||
333 | |||
334 | /** |
||
335 | * @param $name |
||
336 | * @return array |
||
337 | */ |
||
338 | 63 | public function __get($name) |
|
342 | |||
343 | /** |
||
344 | * @param $name |
||
345 | * @param $value |
||
346 | */ |
||
347 | 45 | public function __set($name, $value) |
|
351 | |||
352 | /** |
||
353 | * @return string |
||
354 | */ |
||
355 | 63 | public function getType() |
|
359 | |||
360 | /** |
||
361 | * @param string $type |
||
362 | */ |
||
363 | 45 | public function setType($type) |
|
367 | |||
368 | /** |
||
369 | * init col and val to attributes |
||
370 | * @param $columnsVal |
||
371 | */ |
||
372 | 3 | public function initColVal($columnsVal) |
|
377 | } |
||
378 |