1 | <?php |
||
15 | class Query |
||
16 | { |
||
17 | /** |
||
18 | * |
||
19 | */ |
||
20 | const TYPE_QUERY = 'QUERY'; |
||
21 | /** |
||
22 | * |
||
23 | */ |
||
24 | const TYPE_SELECT = 'SELECT'; |
||
25 | |||
26 | /** |
||
27 | * |
||
28 | */ |
||
29 | const TYPE_INSERT = 'INSERT'; |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | */ |
||
34 | const TYPE_UPDATE = 'UPDATE'; |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | */ |
||
39 | const TYPE_DELETE = 'DELETE'; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | public $table; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $attributes = array( |
||
50 | 'where' => array(), |
||
51 | 'columns' => array() |
||
52 | ); |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $type = "SELECT"; |
||
58 | |||
59 | /** |
||
60 | * @param null $table |
||
61 | */ |
||
62 | public function __construct($table = null) |
||
66 | |||
67 | /** |
||
68 | * @param $queryStr |
||
69 | * @param $params |
||
70 | * @return Query |
||
71 | */ |
||
72 | public static function sql($queryStr, $params = null) |
||
82 | |||
83 | /** |
||
84 | * @param $table |
||
85 | * @return Query |
||
86 | */ |
||
87 | public static function table($table) |
||
91 | |||
92 | /** |
||
93 | * @param $table |
||
94 | */ |
||
95 | public function setTable($table) |
||
99 | |||
100 | /** |
||
101 | * @param $columns |
||
102 | * @return $this |
||
103 | */ |
||
104 | public function select($columns = null) |
||
110 | |||
111 | /** |
||
112 | * @param array $columnsVal |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function insert(array $columnsVal) |
||
122 | |||
123 | |||
124 | /** |
||
125 | * @param $columnsVal |
||
126 | * @return $this |
||
127 | */ |
||
128 | public function update($columnsVal) |
||
135 | |||
136 | public function delete() |
||
141 | |||
142 | /** |
||
143 | * @param $query |
||
144 | * @param string $type |
||
145 | * @return Query |
||
146 | */ |
||
147 | public function whereQ(Query $query, $type = "AND") |
||
154 | |||
155 | /** |
||
156 | * @param $column |
||
157 | * @param $value |
||
158 | * @param string $operator |
||
159 | * @param string $type |
||
160 | * @return Query |
||
161 | */ |
||
162 | public function where($column, $value, $operator = "=", $type = "AND") |
||
167 | |||
168 | /** |
||
169 | * @param $column |
||
170 | * @param $value |
||
171 | * @param string $operator |
||
172 | * @return Query |
||
173 | */ |
||
174 | public function andWhere($column, $value, $operator = "=") |
||
178 | |||
179 | /** |
||
180 | * @param $column |
||
181 | * @param $value |
||
182 | * @param string $operator |
||
183 | * @return Query |
||
184 | */ |
||
185 | public function orWhere($column, $value, $operator = "=") |
||
189 | |||
190 | /** |
||
191 | * @param $column |
||
192 | * @param $value |
||
193 | * @param string $type |
||
194 | * @return Query |
||
195 | */ |
||
196 | public function like($column, $value, $type = "AND") |
||
200 | |||
201 | /** |
||
202 | * @param $column |
||
203 | * @param $value |
||
204 | * @return Query |
||
205 | */ |
||
206 | public function andLike($column, $value) |
||
210 | |||
211 | /** |
||
212 | * @param $column |
||
213 | * @param $value |
||
214 | * @return Query |
||
215 | */ |
||
216 | public function orLike($column, $value) |
||
220 | |||
221 | /** |
||
222 | * @param $column |
||
223 | * @param array $value |
||
224 | * @param string $type |
||
225 | * @return Query |
||
226 | */ |
||
227 | public function between($column, $value = array(), $type = "AND") |
||
235 | |||
236 | /** |
||
237 | * @param $column |
||
238 | * @param array $value |
||
239 | * @return Query |
||
240 | */ |
||
241 | public function andBetween($column, $value = array()) |
||
245 | |||
246 | /** |
||
247 | * @param $column |
||
248 | * @param $value |
||
249 | * @return Query |
||
250 | */ |
||
251 | public function orBetween($column, $value) |
||
255 | |||
256 | /** |
||
257 | * @param Grammar $grammar |
||
258 | * @return array |
||
259 | */ |
||
260 | public function build(Grammar $grammar) |
||
272 | |||
273 | /** |
||
274 | * Clear Query Builder |
||
275 | */ |
||
276 | public function clear() |
||
281 | |||
282 | /** |
||
283 | * @param $name |
||
284 | * @return array |
||
285 | */ |
||
286 | public function __get($name) |
||
290 | |||
291 | /** |
||
292 | * @param $name |
||
293 | * @param $value |
||
294 | */ |
||
295 | public function __set($name, $value) |
||
299 | |||
300 | /** |
||
301 | * @return string |
||
302 | */ |
||
303 | public function getType() |
||
307 | |||
308 | /** |
||
309 | * @param string $type |
||
310 | */ |
||
311 | public function setType($type) |
||
315 | |||
316 | /** |
||
317 | * init col and val to attributes |
||
318 | * @param $columnsVal |
||
319 | */ |
||
320 | public function initColVal($columnsVal) |
||
325 | } |
||
326 |