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 | * @var string |
||
38 | */ |
||
39 | public $table; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $attributes = array( |
||
45 | 'where' => array(), |
||
46 | 'columns' => array() |
||
47 | ); |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $type = "SELECT"; |
||
53 | |||
54 | /** |
||
55 | * @param null $table |
||
56 | */ |
||
57 | public function __construct($table = null) |
||
61 | |||
62 | /** |
||
63 | * @param $queryStr |
||
64 | * @param $params |
||
65 | * @return Query |
||
66 | */ |
||
67 | public static function sql($queryStr, $params = null) |
||
77 | |||
78 | /** |
||
79 | * @param $table |
||
80 | * @return Query |
||
81 | */ |
||
82 | public static function table($table) |
||
86 | |||
87 | /** |
||
88 | * @param $table |
||
89 | */ |
||
90 | public function setTable($table) |
||
94 | |||
95 | /** |
||
96 | * @param $columns |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function select($columns = null) |
||
105 | |||
106 | /** |
||
107 | * @param array $columnsVal |
||
108 | * @return $this |
||
109 | */ |
||
110 | public function insert(array $columnsVal) |
||
117 | |||
118 | |||
119 | /** |
||
120 | * @param $columnsVal |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function update($columnsVal) |
||
130 | |||
131 | /** |
||
132 | * @param $query |
||
133 | * @param string $type |
||
134 | * @return Query |
||
135 | */ |
||
136 | public function whereQ(Query $query, $type = "AND") |
||
143 | |||
144 | /** |
||
145 | * @param $column |
||
146 | * @param $value |
||
147 | * @param string $operator |
||
148 | * @param string $type |
||
149 | * @return Query |
||
150 | */ |
||
151 | public function where($column, $value, $operator = "=", $type = "AND") |
||
156 | |||
157 | /** |
||
158 | * @param $column |
||
159 | * @param $value |
||
160 | * @param string $operator |
||
161 | * @return Query |
||
162 | */ |
||
163 | public function andWhere($column, $value, $operator = "=") |
||
167 | |||
168 | /** |
||
169 | * @param $column |
||
170 | * @param $value |
||
171 | * @param string $operator |
||
172 | * @return Query |
||
173 | */ |
||
174 | public function orWhere($column, $value, $operator = "=") |
||
178 | |||
179 | /** |
||
180 | * @param $column |
||
181 | * @param $value |
||
182 | * @param string $type |
||
183 | * @return Query |
||
184 | */ |
||
185 | public function like($column, $value, $type = "AND") |
||
189 | |||
190 | /** |
||
191 | * @param $column |
||
192 | * @param $value |
||
193 | * @return Query |
||
194 | */ |
||
195 | public function andLike($column, $value) |
||
199 | |||
200 | /** |
||
201 | * @param $column |
||
202 | * @param $value |
||
203 | * @return Query |
||
204 | */ |
||
205 | public function orLike($column, $value) |
||
209 | |||
210 | /** |
||
211 | * @param $column |
||
212 | * @param array $value |
||
213 | * @param string $type |
||
214 | * @return Query |
||
215 | */ |
||
216 | public function between($column, $value = array(), $type = "AND") |
||
224 | |||
225 | /** |
||
226 | * @param $column |
||
227 | * @param array $value |
||
228 | * @return Query |
||
229 | */ |
||
230 | public function andBetween($column, $value = array()) |
||
234 | |||
235 | /** |
||
236 | * @param $column |
||
237 | * @param $value |
||
238 | * @return Query |
||
239 | */ |
||
240 | public function orBetween($column, $value) |
||
244 | |||
245 | /** |
||
246 | * @param Grammar $grammar |
||
247 | * @return array |
||
248 | */ |
||
249 | public function build(Grammar $grammar) |
||
261 | |||
262 | /** |
||
263 | * Clear Query Builder |
||
264 | */ |
||
265 | public function clear() |
||
270 | |||
271 | /** |
||
272 | * @param $name |
||
273 | * @return array |
||
274 | */ |
||
275 | public function __get($name) |
||
279 | |||
280 | /** |
||
281 | * @param $name |
||
282 | * @param $value |
||
283 | */ |
||
284 | public function __set($name, $value) |
||
288 | |||
289 | /** |
||
290 | * @return string |
||
291 | */ |
||
292 | public function getType() |
||
296 | |||
297 | /** |
||
298 | * @param string $type |
||
299 | */ |
||
300 | public function setType($type) |
||
304 | |||
305 | /** |
||
306 | * init col and val to attributes |
||
307 | * @param $columnsVal |
||
308 | */ |
||
309 | public function initColVal($columnsVal) |
||
314 | } |
||
315 |