1 | <?php |
||
16 | class Query |
||
17 | { |
||
18 | /** |
||
19 | * |
||
20 | */ |
||
21 | const TYPE_QUERY = 'QUERY'; |
||
22 | /** |
||
23 | * |
||
24 | */ |
||
25 | const TYPE_SELECT = 'SELECT'; |
||
26 | |||
27 | /** |
||
28 | * |
||
29 | */ |
||
30 | const TYPE_INSERT = 'INSERT'; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | */ |
||
35 | const TYPE_UPDATE = 'UPDATE'; |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | */ |
||
40 | const TYPE_DELETE = 'DELETE'; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | public $table; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $attributes = array( |
||
51 | 'where' => array(), |
||
52 | 'columns' => array() |
||
53 | ); |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $type = "SELECT"; |
||
59 | |||
60 | /** |
||
61 | * @param null $table |
||
62 | */ |
||
63 | public function __construct($table = null) |
||
67 | |||
68 | /** |
||
69 | * @param $queryStr |
||
70 | * @param $params |
||
71 | * @return Query |
||
72 | */ |
||
73 | public static function sql($queryStr, $params = null) |
||
83 | |||
84 | /** |
||
85 | * @param $table |
||
86 | * @return Query |
||
87 | */ |
||
88 | public static function table($table) |
||
92 | |||
93 | /** |
||
94 | * @param $table |
||
95 | */ |
||
96 | public function setTable($table) |
||
100 | |||
101 | /** |
||
102 | * @param $columns |
||
103 | * @return $this |
||
104 | */ |
||
105 | public function select($columns = null) |
||
111 | |||
112 | /** |
||
113 | * @param array $columnsVal |
||
114 | * @return $this |
||
115 | */ |
||
116 | public function insert(array $columnsVal) |
||
123 | |||
124 | |||
125 | /** |
||
126 | * @param $columnsVal |
||
127 | * @return $this |
||
128 | */ |
||
129 | public function update($columnsVal) |
||
136 | |||
137 | /** |
||
138 | * @return $this |
||
139 | */ |
||
140 | public function delete() |
||
145 | |||
146 | /** |
||
147 | * @param $query |
||
148 | * @param string $type |
||
149 | * @return Query |
||
150 | */ |
||
151 | public function whereQ(Query $query, $type = "AND") |
||
158 | |||
159 | /** |
||
160 | * @param $column |
||
161 | * @param $value |
||
162 | * @param string $operator |
||
163 | * @param string $type |
||
164 | * @return Query |
||
165 | */ |
||
166 | public function where($column, $value, $operator = "=", $type = "AND") |
||
171 | |||
172 | /** |
||
173 | * @param $column |
||
174 | * @param $value |
||
175 | * @param string $operator |
||
176 | * @return Query |
||
177 | */ |
||
178 | public function andWhere($column, $value, $operator = "=") |
||
182 | |||
183 | /** |
||
184 | * @param $column |
||
185 | * @param $value |
||
186 | * @param string $operator |
||
187 | * @return Query |
||
188 | */ |
||
189 | public function orWhere($column, $value, $operator = "=") |
||
193 | |||
194 | /** |
||
195 | * @param $column |
||
196 | * @param $value |
||
197 | * @param string $type |
||
198 | * @return Query |
||
199 | */ |
||
200 | public function like($column, $value, $type = "AND") |
||
204 | |||
205 | /** |
||
206 | * @param $column |
||
207 | * @param $value |
||
208 | * @return Query |
||
209 | */ |
||
210 | public function andLike($column, $value) |
||
214 | |||
215 | /** |
||
216 | * @param $column |
||
217 | * @param $value |
||
218 | * @return Query |
||
219 | */ |
||
220 | public function orLike($column, $value) |
||
224 | |||
225 | /** |
||
226 | * @param $column |
||
227 | * @param array $value |
||
228 | * @param string $type |
||
229 | * @return Query |
||
230 | */ |
||
231 | public function between($column, $value = array(), $type = "AND") |
||
239 | |||
240 | /** |
||
241 | * @param $column |
||
242 | * @param array $value |
||
243 | * @return Query |
||
244 | */ |
||
245 | public function andBetween($column, $value = array()) |
||
249 | |||
250 | /** |
||
251 | * @param $column |
||
252 | * @param $value |
||
253 | * @return Query |
||
254 | */ |
||
255 | public function orBetween($column, $value) |
||
259 | |||
260 | /** |
||
261 | * @param $column |
||
262 | * @param $order |
||
263 | * @return $this |
||
264 | */ |
||
265 | public function sort($column, $order) |
||
274 | |||
275 | /** |
||
276 | * @param $column |
||
277 | * @return Query |
||
278 | */ |
||
279 | public function asc($column) |
||
283 | |||
284 | /** |
||
285 | * @param $column |
||
286 | * @return Query |
||
287 | */ |
||
288 | public function desc($column) |
||
292 | |||
293 | /** |
||
294 | * @param Grammar $grammar |
||
295 | * @return array |
||
296 | */ |
||
297 | public function build(Grammar $grammar) |
||
309 | |||
310 | /** |
||
311 | * Clear Query Builder |
||
312 | */ |
||
313 | public function clear() |
||
318 | |||
319 | /** |
||
320 | * @param $name |
||
321 | * @return array |
||
322 | */ |
||
323 | public function __get($name) |
||
327 | |||
328 | /** |
||
329 | * @param $name |
||
330 | * @param $value |
||
331 | */ |
||
332 | public function __set($name, $value) |
||
336 | |||
337 | /** |
||
338 | * @return string |
||
339 | */ |
||
340 | public function getType() |
||
344 | |||
345 | /** |
||
346 | * @param string $type |
||
347 | */ |
||
348 | public function setType($type) |
||
352 | |||
353 | /** |
||
354 | * init col and val to attributes |
||
355 | * @param $columnsVal |
||
356 | */ |
||
357 | public function initColVal($columnsVal) |
||
362 | } |
||
363 |