1 | <?php |
||
2 | class OctaORM{ |
||
3 | |||
4 | protected $redbean; |
||
5 | protected $db_field; |
||
6 | |||
7 | var $last_id; |
||
8 | var $last_query; |
||
9 | |||
10 | var $get; |
||
11 | var $select; |
||
12 | var $where; |
||
13 | var $or_where; |
||
14 | var $order_by; |
||
15 | var $join; |
||
16 | var $group_by; |
||
17 | var $table; |
||
18 | var $limit; |
||
19 | var $offset; |
||
20 | var $where_in; |
||
21 | var $or_where_in; |
||
22 | var $where_not_in; |
||
23 | var $or_where_not_in; |
||
24 | var $like; |
||
25 | var $or_like; |
||
26 | var $not_like; |
||
27 | var $or_not_like; |
||
28 | var $row; |
||
29 | var $num_rows; |
||
30 | var $result; |
||
31 | |||
32 | public function __construct($db){ |
||
33 | include_once('RedBean.php'); |
||
34 | $this->redbean = new R(); |
||
35 | $this->db_field = $db; |
||
36 | |||
37 | if(!$this->redbean->testConnection()){ |
||
38 | $conn = $this->initiate_database_connection($db); |
||
39 | $this->redbean->setup($conn); |
||
40 | $this->redbean->useFeatureSet( 'novice/latest' ); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | public function initiate_database_connection($db){ |
||
45 | $DB_HOST = $db['hostname']; |
||
46 | $DB_USERNAME = $db['username']; |
||
47 | $DB_PASSWORD = $db['password']; |
||
48 | $DB_NAME = $db['database']; |
||
49 | $DB_con = null; |
||
50 | |||
51 | $DB_con = new PDO("mysql:host=$DB_HOST", $DB_USERNAME, $DB_PASSWORD); |
||
52 | $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
||
53 | |||
54 | $DB_con->exec("CREATE DATABASE IF NOT EXISTS $DB_NAME;"); |
||
55 | |||
56 | $DB_con = new PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}",$DB_USERNAME,$DB_PASSWORD); |
||
57 | $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
||
58 | return $DB_con; |
||
59 | } |
||
60 | |||
61 | public function insert_id(){ |
||
62 | return $this->last_id; |
||
63 | } |
||
64 | |||
65 | public function last_query(){ |
||
66 | return $this->last_query; |
||
67 | } |
||
68 | |||
69 | public function insert($array,$table){ |
||
70 | $data = $this->redbean->dispense($table); |
||
71 | |||
72 | if($array){ |
||
73 | foreach($array as $key=>$row){ |
||
74 | $data->$key = $row; |
||
75 | } |
||
76 | } |
||
77 | |||
78 | $this->last_id = $this->redbean->store($data); |
||
79 | return ($this->last_id) ? true : false; |
||
80 | } |
||
81 | |||
82 | public function insert_batch($array,$table){ |
||
83 | $data = array(); |
||
84 | |||
85 | if($array){ |
||
86 | foreach($array as $key_ib=>$row_ib){ |
||
87 | |||
88 | $data[$key_ib]=$this->redbean->dispense($table); |
||
89 | $table_fields = []; |
||
90 | $table_fields_val = []; |
||
91 | |||
92 | if($row_ib){ |
||
93 | foreach($row_ib as $row=>$val){ |
||
94 | $table_fields[] = $row; |
||
95 | $table_fields_val[] = $val; |
||
96 | } |
||
97 | |||
98 | if($table_fields && $table_fields_val){ |
||
99 | foreach($table_fields as $key=>$row){ |
||
100 | $data[$key_ib]->$row = $table_fields_val[$key]; |
||
101 | } |
||
102 | |||
103 | }else{ |
||
104 | return false; |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | |||
110 | $result = $this->redbean->storeAll($data); |
||
111 | return ($result) ? true : false; |
||
112 | } |
||
113 | |||
114 | public function update($table,$array,$id){ |
||
115 | $data = $this->redbean->load($table, $id); |
||
116 | |||
117 | if($array){ |
||
118 | foreach($array as $key=>$row){ |
||
119 | $data->$key = $row; |
||
120 | } |
||
121 | } |
||
122 | |||
123 | $result = $this->redbean->store($data); |
||
124 | return ($result) ? true : false; |
||
125 | } |
||
126 | |||
127 | public function update_batch($table,$array,$where){ |
||
128 | if($array){ |
||
129 | foreach($array as $key_ub=>$row_ub){ |
||
130 | $where_key = ''; |
||
131 | $table_fields = []; |
||
132 | $table_fields_val = []; |
||
133 | |||
134 | if($row_ub){ |
||
135 | foreach($row_ub as $row=>$val){ |
||
136 | |||
137 | if($row === $where){ |
||
138 | $where_key = $val; |
||
139 | } |
||
140 | |||
141 | if($row !== $where){ |
||
142 | $table_fields[] = $row; |
||
143 | $table_fields_val[] = $val; |
||
144 | } |
||
145 | } |
||
146 | |||
147 | $data = $this->redbean->load($table, $where_key); |
||
148 | if($table_fields && $table_fields_val){ |
||
149 | foreach($table_fields as $key=>$row){ |
||
150 | $data->$row = $table_fields_val[$key]; |
||
151 | } |
||
152 | |||
153 | }else{ |
||
154 | return false; |
||
155 | } |
||
156 | |||
157 | $this->redbean->store($data); |
||
158 | } |
||
159 | } |
||
160 | } |
||
161 | |||
162 | return true; |
||
163 | } |
||
164 | |||
165 | public function delete($table,$id){ |
||
166 | if(is_array($id)){ |
||
167 | if($id){ |
||
168 | foreach($id as $key=>$row){ |
||
169 | $this->redbean->trash($table,$row); |
||
170 | } |
||
171 | |||
172 | return true; |
||
173 | } |
||
174 | |||
175 | }else{ |
||
176 | $this->redbean->trash($table,$id); |
||
177 | return true; |
||
178 | } |
||
179 | } |
||
180 | |||
181 | public function delete_all($table){ |
||
182 | $result = $this->redbean->wipe($table); |
||
183 | return ($result) ? true : false; |
||
184 | } |
||
185 | |||
186 | public function select($data){ |
||
187 | $reset = []; |
||
188 | if($data){ |
||
189 | foreach($data as $key=>$row){ |
||
190 | array_push($reset,$row); |
||
191 | } |
||
192 | } |
||
193 | |||
194 | $this->select = $reset; |
||
195 | return $this->select; |
||
196 | } |
||
197 | |||
198 | public function where($data=null,$match=null){ |
||
199 | $tmp_where = ''; |
||
200 | $arr_check = false; |
||
201 | if($data){ |
||
202 | if(is_array($data)){ |
||
203 | end($data); |
||
204 | $last_element = key($data); |
||
205 | |||
206 | if($data){ |
||
207 | $arr_check = true; |
||
208 | foreach($data as $key=>$row){ |
||
209 | if($key == $last_element){ |
||
210 | $tmp_where .= $key."='".$row."'"; |
||
211 | }else{ |
||
212 | $tmp_where .= $key."='".$row."' AND "; |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | }else{ |
||
217 | $arr_check = false; |
||
218 | $tmp_where = "WHERE ".$data."='".$match."'"; |
||
219 | } |
||
220 | } |
||
221 | |||
222 | $this->where = ($arr_check) ? "WHERE ".$tmp_where : $tmp_where; |
||
223 | } |
||
224 | |||
225 | public function or_where($data=null,$match=null){ |
||
226 | $tmp_or_where = ''; |
||
227 | $arr_check = false; |
||
228 | if($data){ |
||
229 | if(is_array($data)){ |
||
230 | end($data); |
||
231 | $last_element = key($data); |
||
232 | $arr_check = true; |
||
233 | |||
234 | if($data){ |
||
235 | foreach($data as $key=>$row){ |
||
236 | if($key == $last_element){ |
||
237 | $tmp_or_where .= $key."='".$row."'"; |
||
238 | }else{ |
||
239 | $tmp_or_where .= $key."='".$row."' AND "; |
||
240 | } |
||
241 | } |
||
242 | } |
||
243 | }else{ |
||
244 | $arr_check = false; |
||
245 | $tmp_or_where = "OR ".$data."='".$match."'"; |
||
246 | } |
||
247 | } |
||
248 | |||
249 | $this->or_where = ($arr_check == false) ? $tmp_or_where : "OR ".$tmp_or_where; |
||
0 ignored issues
–
show
|
|||
250 | } |
||
251 | |||
252 | public function where_in($field,$data){ |
||
253 | $where_in_fields = ''; |
||
254 | $last_key = end(array_keys($data)); |
||
255 | if($data){ |
||
256 | foreach($data as $key=>$row){ |
||
257 | if($key == $last_key){ |
||
258 | $where_in_fields .= $row; |
||
259 | }else{ |
||
260 | $where_in_fields .= $row.","; |
||
261 | } |
||
262 | } |
||
263 | } |
||
264 | |||
265 | $this->where_in = 'WHERE '.$field.' IN ('.$where_in_fields.')'; |
||
266 | } |
||
267 | |||
268 | public function or_where_in($field,$data){ |
||
269 | $where_in_fields = ''; |
||
270 | $last_key = end(array_keys($data)); |
||
271 | if($data){ |
||
272 | foreach($data as $key=>$row){ |
||
273 | if($key == $last_key){ |
||
274 | $where_in_fields .= $row; |
||
275 | }else{ |
||
276 | $where_in_fields .= $row.","; |
||
277 | } |
||
278 | } |
||
279 | } |
||
280 | |||
281 | $this->or_where_in = 'OR '.$field.' IN ('.$where_in_fields.')'; |
||
282 | } |
||
283 | |||
284 | public function where_not_in($field,$data){ |
||
285 | $where_in_fields = ''; |
||
286 | $last_key = end(array_keys($data)); |
||
287 | if($data){ |
||
288 | foreach($data as $key=>$row){ |
||
289 | if($key == $last_key){ |
||
290 | $where_in_fields .= $row; |
||
291 | }else{ |
||
292 | $where_in_fields .= $row.","; |
||
293 | } |
||
294 | } |
||
295 | } |
||
296 | |||
297 | $this->where_not_in = 'WHERE '.$field.' NOT IN ('.$where_in_fields.')'; |
||
298 | } |
||
299 | |||
300 | public function or_where_not_in($field,$data){ |
||
301 | $where_in_fields = ''; |
||
302 | $last_key = end(array_keys($data)); |
||
303 | if($data){ |
||
304 | foreach($data as $key=>$row){ |
||
305 | if($key == $last_key){ |
||
306 | $where_in_fields .= $row; |
||
307 | }else{ |
||
308 | $where_in_fields .= $row.","; |
||
309 | } |
||
310 | } |
||
311 | } |
||
312 | |||
313 | $this->or_where_not_in = 'OR '.$field.' NOT IN ('.$where_in_fields.')'; |
||
314 | } |
||
315 | |||
316 | public function like($data=null,$match=null){ |
||
317 | $tmp_like = ''; |
||
318 | $arr_check = false; |
||
319 | if($data){ |
||
320 | if(is_array($data)){ |
||
321 | end($data); |
||
322 | $last_element = key($data); |
||
323 | |||
324 | if($data){ |
||
325 | $arr_check = true; |
||
326 | foreach($data as $key=>$row){ |
||
327 | if($key == $last_element){ |
||
328 | $tmp_like .= $key." LIKE '%".$row."%'"; |
||
329 | }else{ |
||
330 | $tmp_like .= $key." LIKE '%".$row."%' AND "; |
||
331 | } |
||
332 | } |
||
333 | } |
||
334 | }else{ |
||
335 | $arr_check = false; |
||
336 | $tmp_like = "WHERE ".$data." LIKE '%".$match."%'"; |
||
337 | } |
||
338 | |||
339 | } |
||
340 | |||
341 | $this->like = ($arr_check == false) ? $tmp_like : "WHERE ".$tmp_like; |
||
342 | } |
||
343 | |||
344 | public function or_like($data=null,$match=null){ |
||
345 | $tmp_or_like = ''; |
||
346 | if($data){ |
||
347 | if(is_array($data)){ |
||
348 | end($data); |
||
349 | $last_element = key($data); |
||
350 | |||
351 | if($data){ |
||
352 | foreach($data as $key=>$row){ |
||
353 | if($key == $last_element){ |
||
354 | $tmp_or_like .= "OR ".$key." LIKE '%".$row."%'"; |
||
355 | }else{ |
||
356 | $tmp_or_like .= "OR ".$key." LIKE '%".$row."%' AND "; |
||
357 | } |
||
358 | } |
||
359 | } |
||
360 | }else{ |
||
361 | $tmp_or_like = "OR ".$data." LIKE '%".$match."%'"; |
||
362 | } |
||
363 | } |
||
364 | |||
365 | $this->or_like = $tmp_or_like; |
||
366 | } |
||
367 | |||
368 | public function not_like($data=null,$match=null){ |
||
369 | $tmp_like = ''; |
||
370 | $arr_check = false; |
||
371 | if($data){ |
||
372 | if(is_array($data)){ |
||
373 | end($data); |
||
374 | $last_element = key($data); |
||
375 | |||
376 | if($data){ |
||
377 | $arr_check = true; |
||
378 | foreach($data as $key=>$row){ |
||
379 | if($key == $last_element){ |
||
380 | $tmp_like .= $key." NOT LIKE '%".$row."%'"; |
||
381 | }else{ |
||
382 | $tmp_like .= $key." NOT LIKE '%".$row."%' AND "; |
||
383 | } |
||
384 | } |
||
385 | } |
||
386 | }else{ |
||
387 | $arr_check = false; |
||
388 | $tmp_like = "WHERE ".$data." NOT LIKE '%".$match."%'"; |
||
389 | } |
||
390 | |||
391 | } |
||
392 | |||
393 | $this->like = ($arr_check == false) ? $tmp_like : "WHERE ".$tmp_like; |
||
394 | } |
||
395 | |||
396 | public function or_not_like($data=null,$match=null){ |
||
397 | $tmp_or_like = ''; |
||
398 | if($data){ |
||
399 | if(is_array($data)){ |
||
400 | end($data); |
||
401 | $last_element = key($data); |
||
402 | |||
403 | if($data){ |
||
404 | foreach($data as $key=>$row){ |
||
405 | if($key == $last_element){ |
||
406 | $tmp_or_like .= "OR ".$key." NOT LIKE '%".$row."%'"; |
||
407 | }else{ |
||
408 | $tmp_or_like .= "OR ".$key." NOT LIKE '%".$row."%' AND "; |
||
409 | } |
||
410 | } |
||
411 | } |
||
412 | }else{ |
||
413 | $tmp_or_like = "OR ".$data." NOT LIKE '%".$match."%'"; |
||
414 | } |
||
415 | } |
||
416 | |||
417 | $this->or_like = $tmp_or_like; |
||
418 | } |
||
419 | |||
420 | public function order_by($field,$sort){ |
||
421 | $this->order_by = $field.' '.$sort; |
||
422 | } |
||
423 | |||
424 | public function join($table,$joint,$join_type="INNER"){ |
||
425 | $this->join = $join_type.' JOIN '.$table.' ON '.$joint; |
||
426 | } |
||
427 | |||
428 | public function group_by($field){ |
||
429 | $this->group_by = 'GROUP BY '.$field; |
||
430 | } |
||
431 | |||
432 | public function get($table=null,$limit=null,$offset=null){ |
||
433 | $this->table = $table; |
||
434 | $this->limit = $limit; |
||
435 | $this->offset = $offset; |
||
436 | } |
||
437 | |||
438 | public function clear_global_var(){ |
||
439 | $this->select = ''; |
||
440 | $this->where = ''; |
||
441 | $this->or_where = ''; |
||
442 | $this->order_by = ''; |
||
443 | $this->join = ''; |
||
444 | $this->group_by = ''; |
||
445 | $this->limit = ''; |
||
446 | $this->table = ''; |
||
447 | $this->offset = ''; |
||
448 | $this->where_in = ''; |
||
449 | $this->or_where_in = ''; |
||
450 | $this->where_not_in = ''; |
||
451 | $this->or_where_not_in = ''; |
||
452 | $this->like = ''; |
||
453 | $this->or_like = ''; |
||
454 | $this->not_like = ''; |
||
455 | $this->or_not_like = ''; |
||
456 | $this->row = ''; |
||
457 | $this->num_rows = ''; |
||
458 | $this->result = ''; |
||
459 | } |
||
460 | |||
461 | public function row(){ |
||
462 | /*init var*/ |
||
463 | $result = []; |
||
464 | $select = ($this->select) ? implode(',',$this->select) : '*'; |
||
465 | $order_by = ($this->order_by) ? 'ORDER BY '.$this->order_by : ''; |
||
466 | $join = ($this->join) ? $this->join : ''; |
||
467 | $group_by = ($this->group_by) ? $this->group_by : ''; |
||
468 | $limit = ($this->limit) ? 'LIMIT '.$this->limit : ''; |
||
469 | $offset = ($this->offset) ? 'OFFSET '.$this->offset : ''; |
||
470 | $table = ($this->table) ? $this->table : ''; |
||
471 | |||
472 | $where = ($this->where) ? $this->where : ''; |
||
473 | $or_where = ($this->or_where) ? $this->or_where : ''; |
||
474 | $where_in = ($this->where_in) ? $this->where_in : ''; |
||
475 | $or_where_in = ($this->or_where_in) ? $this->or_where_in : ''; |
||
476 | $where_not_in = ($this->where_not_in) ? $this->where_not_in : ''; |
||
477 | $or_where_not_in = ($this->or_where_not_in) ? $this->or_where_not_in : ''; |
||
478 | |||
479 | $like = ($this->like) ? $this->like : ''; |
||
480 | $or_like = ($this->or_like) ? $this->or_like : ''; |
||
481 | $not_like = ($this->not_like) ? $this->not_like : ''; |
||
482 | $or_not_like = ($this->or_not_like) ? $this->or_not_like : ''; |
||
483 | /*end init var*/ |
||
484 | |||
485 | $this->row = "SELECT {$select} FROM {$table} {$join} {$where} {$or_where} {$where_in} {$or_where_in} {$where_not_in} {$or_where_not_in} {$like} {$or_like} {$not_like} {$or_not_like} {$group_by} {$order_by} {$limit} {$offset}"; |
||
486 | $this->last_query = $this->row; |
||
487 | $data = $this->redbean->getRow($this->row); |
||
488 | if($data){ |
||
489 | foreach($data as $key=>$row){ |
||
490 | $result[$key] = $row; |
||
491 | } |
||
492 | } |
||
493 | |||
494 | /*clear global variables*/ |
||
495 | $this->clear_global_var(); |
||
496 | /*end clearing global variables*/ |
||
497 | |||
498 | return $result; |
||
499 | } |
||
500 | |||
501 | public function num_rows(){ |
||
502 | /*init var*/ |
||
503 | $result = 0;#array(); |
||
504 | $select = ($this->select) ? implode(',',$this->select) : '*'; |
||
505 | $order_by = ($this->order_by) ? 'ORDER BY '.$this->order_by : ''; |
||
506 | $join = ($this->join) ? $this->join : ''; |
||
507 | $group_by = ($this->group_by) ? $this->group_by : ''; |
||
508 | $limit = ($this->limit) ? 'LIMIT '.$this->limit : ''; |
||
509 | $offset = ($this->offset) ? 'OFFSET '.$this->offset : ''; |
||
510 | $table = ($this->table) ? $this->table : ''; |
||
511 | |||
512 | $where = ($this->where) ? $this->where : ''; |
||
513 | $or_where = ($this->or_where) ? $this->or_where : ''; |
||
514 | $where_in = ($this->where_in) ? $this->where_in : ''; |
||
515 | $or_where_in = ($this->or_where_in) ? $this->or_where_in : ''; |
||
516 | $where_not_in = ($this->where_not_in) ? $this->where_not_in : ''; |
||
517 | $or_where_not_in = ($this->or_where_not_in) ? $this->or_where_not_in : ''; |
||
518 | |||
519 | $like = ($this->like) ? $this->like : ''; |
||
520 | $or_like = ($this->or_like) ? $this->or_like : ''; |
||
521 | $not_like = ($this->not_like) ? $this->not_like : ''; |
||
522 | $or_not_like = ($this->or_not_like) ? $this->or_not_like : ''; |
||
523 | /*end init var*/ |
||
524 | |||
525 | $this->num_rows = "SELECT {$select} FROM {$table} {$join} {$where} {$or_where} {$where_in} {$or_where_in} {$where_not_in} {$or_where_not_in} {$like} {$or_like} {$not_like} {$or_not_like} {$group_by} {$order_by} {$limit} {$offset}"; |
||
526 | $this->last_query = $this->num_rows; |
||
527 | $data = $this->redbean->exec($this->num_rows); |
||
528 | $result = $result + $data; |
||
529 | |||
530 | /*clear global variables*/ |
||
531 | $this->clear_global_var(); |
||
532 | /*end clearing global variables*/ |
||
533 | |||
534 | return $result; |
||
535 | } |
||
536 | |||
537 | public function result(){ |
||
538 | /*init var*/ |
||
539 | $result = array(); |
||
540 | $select = ($this->select) ? implode(',',$this->select) : '*'; |
||
541 | $order_by = ($this->order_by) ? 'ORDER BY '.$this->order_by : ''; |
||
542 | $join = ($this->join) ? $this->join : ''; |
||
543 | $group_by = ($this->group_by) ? $this->group_by : ''; |
||
544 | $limit = ($this->limit) ? 'LIMIT '.$this->limit : ''; |
||
545 | $offset = ($this->offset) ? 'OFFSET '.$this->offset : ''; |
||
546 | $table = ($this->table) ? $this->table : ''; |
||
547 | |||
548 | $where = ($this->where) ? $this->where : ''; |
||
549 | $or_where = ($this->or_where) ? $this->or_where : ''; |
||
550 | $where_in = ($this->where_in) ? $this->where_in : ''; |
||
551 | $or_where_in = ($this->or_where_in) ? $this->or_where_in : ''; |
||
552 | $where_not_in = ($this->where_not_in) ? $this->where_not_in : ''; |
||
553 | $or_where_not_in = ($this->or_where_not_in) ? $this->or_where_not_in : ''; |
||
554 | |||
555 | $like = ($this->like) ? $this->like : ''; |
||
556 | $or_like = ($this->or_like) ? $this->or_like : ''; |
||
557 | $not_like = ($this->not_like) ? $this->not_like : ''; |
||
558 | $or_not_like = ($this->or_not_like) ? $this->or_not_like : ''; |
||
559 | /*end init var*/ |
||
560 | |||
561 | #$this->get($table,$limit,$offset); |
||
562 | |||
563 | $this->result = "SELECT {$select} FROM {$table} {$join} {$where} {$or_where} {$where_in} {$or_where_in} {$where_not_in} {$or_where_not_in} {$like} {$or_like} {$not_like} {$or_not_like} {$group_by} {$order_by} {$limit} {$offset}"; |
||
564 | $this->last_query = $this->result; |
||
565 | $data = $this->redbean->getAll($this->result); |
||
566 | if($data){ |
||
567 | foreach($data as $key=>$row){ |
||
568 | $result[$key] = (object)$row; |
||
569 | } |
||
570 | } |
||
571 | |||
572 | /*clear global variables*/ |
||
573 | $this->clear_global_var(); |
||
574 | /*end clearing global variables*/ |
||
575 | |||
576 | return $result; |
||
577 | } |
||
578 | |||
579 | /*Database*/ |
||
580 | public function wipe($beanType){ |
||
581 | $result = $this->redbean->wipe($beanType); |
||
582 | return ($result) ? $result : false; |
||
583 | } |
||
584 | |||
585 | public function dispense($data){ |
||
586 | $result = $this->redbean->dispense($data); |
||
587 | return ($result) ? true : false; |
||
588 | } |
||
589 | |||
590 | public function store($data){ |
||
591 | $result = $this->redbean->store($data); |
||
592 | return ($result) ? true : false; |
||
593 | } |
||
594 | |||
595 | public function inspect($data){ |
||
596 | if($data){ |
||
597 | if(is_array($data)){ |
||
598 | |||
599 | $result = array(); |
||
600 | foreach($data as $key=>$row){ |
||
601 | $result[$key]=$this->redbean->inspect($row); |
||
602 | } |
||
603 | |||
604 | return ($result) ? $result : false; |
||
605 | |||
606 | }else{ |
||
607 | $this->redbean->inspect($data); |
||
608 | return true; |
||
609 | } |
||
610 | } |
||
611 | } |
||
612 | |||
613 | public function get_all_tables(){ |
||
614 | $result = $this->redbean->inspect(); |
||
615 | return ($result) ? $result : false; |
||
616 | } |
||
617 | |||
618 | public function add_database($db_name,$hostname,$user_name,$password,$frozen=null){ |
||
619 | $result = $this->redbean->addDatabase($db_name, $hostname, $user_name, $password, $frozen ); |
||
620 | return ($result) ? true : false; |
||
621 | } |
||
622 | |||
623 | public function select_database($db_name){ |
||
624 | $result = $this->redbean->selectDatabase($db_name); |
||
625 | return ($result) ? true : false; |
||
626 | } |
||
627 | |||
628 | public function set_database(){ |
||
629 | $result = $this->redbean->selectDatabase('default'); |
||
630 | return ($result) ? true : false; |
||
631 | } |
||
632 | |||
633 | public function begin(){ |
||
634 | $result = $this->redbean->begin(); |
||
635 | return ($result) ? true : false; |
||
636 | } |
||
637 | |||
638 | public function commit(){ |
||
639 | $result = $this->redbean->commit(); |
||
640 | return ($result) ? true : false; |
||
641 | } |
||
642 | |||
643 | public function roll_back(){ |
||
644 | $result = $this->redbean->rollback(); |
||
645 | return ($result) ? true : false; |
||
646 | } |
||
647 | |||
648 | public function reset_query_count(){ |
||
649 | $result = $this->redbean->resetQueryCount(); |
||
650 | return ($result) ? true : false; |
||
651 | } |
||
652 | |||
653 | public function get_query_count(){ |
||
654 | $result = $this->redbean->getQueryCount(); |
||
655 | return ($result) ? $result : false; |
||
656 | } |
||
657 | |||
658 | public function start_logging(){ |
||
659 | $result = $this->redbean->startLogging(); |
||
660 | return ($result) ? true : false; |
||
661 | } |
||
662 | |||
663 | public function get_logs(){ |
||
664 | $result = $this->redbean->getLogs(); |
||
665 | return ($result) ? $result : false; |
||
666 | } |
||
667 | |||
668 | /*querying*/ |
||
669 | public function exec($data){ |
||
670 | $result = $this->redbean->exec($data); |
||
671 | return ($result) ? $result : false; |
||
672 | } |
||
673 | |||
674 | public function get_all($table){ |
||
675 | $result = $this->redbean->getAll($table); |
||
676 | return ($result) ? $result : false; |
||
677 | } |
||
678 | |||
679 | public function get_row($data){ |
||
680 | $result = $this->redbean->getRow($data); |
||
681 | return ($result) ? $result : false; |
||
682 | } |
||
683 | |||
684 | public function get_column($data){ |
||
685 | $result = $this->redbean->getCol($data); |
||
686 | return ($result) ? $result : false; |
||
687 | } |
||
688 | |||
689 | public function get_cell($data){ |
||
690 | $result = $this->redbean->getCell($data); |
||
691 | return ($result) ? $result : false; |
||
692 | } |
||
693 | |||
694 | public function get_assoc($data){ |
||
695 | $result = $this->redbean->getAssoc($data); |
||
696 | return ($result) ? $result : false; |
||
697 | } |
||
698 | |||
699 | public function get_inserted_id(){ |
||
700 | $result = $this->redbean->getInsertID(); |
||
701 | return ($result) ? $result : false; |
||
702 | } |
||
703 | |||
704 | public function convert_to_beans($type,$rows,$metamask=null){ |
||
705 | $result = $this->redbean->convertToBeans( $type, $rows, $metamask ); |
||
706 | return ($result) ? $result : false; |
||
707 | } |
||
708 | |||
709 | /*Data Tools*/ |
||
710 | /*this will return an html data*/ |
||
711 | public function get_look($sql, $bindings = array(), $keys = array( 'selected', 'id', 'name' ), $template = '<option %s value="%s">%s</option>', $filter = 'trim', $glue = '' ){ |
||
712 | $result = $this->redbean->getLook()->look($sql,$bindings,$keys,$template,$filter,$glue); |
||
713 | return ($result) ? $result : false; |
||
714 | } |
||
715 | |||
716 | public function match_up($type, $sql, $bindings = array(), $onFoundDo = NULL, $onNotFoundDo = NULL, &$bean = NULL){ |
||
717 | $result = $this->redbean->matchUp($type, $sql, $bindings, $onFoundDo, $onNotFoundDo, $bean); |
||
718 | return ($result) ? $result : false; |
||
719 | } |
||
720 | |||
721 | public function csv($sql, $id = array(), $bindings = array()){ |
||
722 | $result = $this->redbean->csv($sql,$id,$bindings); |
||
723 | return ($result) ? true : false; |
||
724 | } |
||
725 | |||
726 | public function find_all($table){ |
||
727 | $result = $this->redbean->findAll($table); |
||
728 | return ($result) ? $result : false; |
||
729 | } |
||
730 | |||
731 | public function find($type,$sql,$bindings){ |
||
732 | $result = $this->redbean->find($type,$sql,$bindings); |
||
733 | return ($result) ? $result : false; |
||
734 | } |
||
735 | |||
736 | public function csv_result(){ |
||
737 | /*init var*/ |
||
738 | $result = array(); |
||
739 | $select = ($this->select) ? implode(',',$this->select) : '*'; |
||
740 | $order_by = ($this->order_by) ? 'ORDER BY '.$this->order_by : ''; |
||
741 | $join = ($this->join) ? $this->join : ''; |
||
742 | $group_by = ($this->group_by) ? $this->group_by : ''; |
||
743 | $limit = ($this->limit) ? 'LIMIT '.$this->limit : ''; |
||
744 | $table = ($this->table) ? $this->table : ''; |
||
745 | |||
746 | $where = ($this->where) ? $this->where : ''; |
||
747 | $or_where = ($this->or_where) ? $this->or_where : ''; |
||
748 | $where_in = ($this->where_in) ? $this->where_in : ''; |
||
749 | $or_where_in = ($this->or_where_in) ? $this->or_where_in : ''; |
||
750 | $where_not_in = ($this->where_not_in) ? $this->where_not_in : ''; |
||
751 | $or_where_not_in = ($this->or_where_not_in) ? $this->or_where_not_in : ''; |
||
752 | |||
753 | $like = ($this->like) ? $this->like : ''; |
||
754 | $or_like = ($this->or_like) ? $this->or_like : ''; |
||
755 | $not_like = ($this->not_like) ? $this->not_like : ''; |
||
756 | $or_not_like = ($this->or_not_like) ? $this->or_not_like : ''; |
||
757 | /*end init var*/ |
||
758 | |||
759 | $this->last_query = "SELECT {$select} FROM {$table} {$join} {$where} {$or_where} {$where_in} {$or_where_in} {$where_not_in} {$or_where_not_in} {$like} {$or_like} {$not_like} {$or_not_like} {$group_by} {$order_by} {$limit}"; |
||
760 | $data = $this->redbean->csv("SELECT {$select} FROM {$table} {$join} {$where} {$or_where} {$where_in} {$or_where_in} {$where_not_in} {$or_where_not_in} {$like} {$or_like} {$not_like} {$or_not_like} {$group_by} {$order_by} {$limit}"); |
||
761 | if($data){ |
||
762 | foreach($data as $key=>$row){ |
||
763 | $result[$key] = (object)$row; |
||
764 | } |
||
765 | } |
||
766 | |||
767 | /*clear global variables*/ |
||
768 | $this->clear_global_var(); |
||
769 | /*end clearing global variables*/ |
||
770 | |||
771 | return $result; |
||
772 | } |
||
773 | |||
774 | /*Fluid and Frozen*/ |
||
775 | public function freeze($data=null){ |
||
776 | if($data){ |
||
777 | if(is_array($data)){ |
||
778 | if($data){ |
||
779 | |||
780 | $data = array(); |
||
781 | foreach($data as $key=>$row){ |
||
782 | $data[$key] = $row; |
||
783 | } |
||
784 | |||
785 | $this->redbean->freeze($data); |
||
786 | } |
||
787 | } |
||
788 | }else{ |
||
789 | $this->redbean->freeze(TRUE); |
||
790 | } |
||
791 | return true; |
||
792 | } |
||
793 | |||
794 | /*Debugging*/ |
||
795 | public function fancy_debug($toggle = TRUE){ |
||
796 | $result = $this->redbean->fancyDebug($toggle); |
||
797 | return ($result) ? $result : false; |
||
798 | } |
||
799 | |||
800 | /*value "true", "false"*/ |
||
801 | public function debug($tf = TRUE, $mode = 0){ |
||
802 | $result = $this->redbean->debug($tf,$mode); |
||
803 | return ($result) ? $result : false; |
||
804 | } |
||
805 | |||
806 | public function dump($data){ |
||
807 | $result = $this->redbean->dump($data); |
||
808 | return ($result) ? $result : false; |
||
809 | } |
||
810 | |||
811 | public function test_connection(){ |
||
812 | $result = $this->redbean->testConnection(); |
||
813 | return ($result) ? $result : false; |
||
814 | } |
||
815 | |||
816 | /*Aliases*/ |
||
817 | public function load($oodb, $types, $id){ |
||
818 | $result = $this->redbean->load($oodb, $types, $id); |
||
819 | return ($result) ? $result : false; |
||
820 | } |
||
821 | |||
822 | public function fetch_as($type){ |
||
823 | $result = $this->redbean->fetchAs($type); |
||
824 | return ($result) ? $result : false; |
||
825 | } |
||
826 | |||
827 | public function alias($alias_name){ |
||
828 | $result = $this->redbean->alias($alias_name); |
||
829 | return ($result) ? $result : false; |
||
830 | } |
||
831 | |||
832 | /*Count*/ |
||
833 | public function count(){ |
||
834 | $result = $this->redbean->count(); |
||
835 | return ($result) ? $result : false; |
||
836 | } |
||
837 | |||
838 | public function count_own($type){ |
||
839 | $result = $this->redbean->countOwn($type); |
||
840 | return ($result) ? $result : false; |
||
841 | } |
||
842 | |||
843 | public function count_shared($type){ |
||
844 | $result = $this->redbean->countOwn($type); |
||
845 | return ($result) ? $result : false; |
||
846 | } |
||
847 | |||
848 | /*Labels, Enums, Tags*/ |
||
849 | public function dispense_labels($type,$labels){ |
||
850 | $result = $this->redbean->dispenseLabels($type,$labels); |
||
851 | return ($result) ? $result : false; |
||
852 | } |
||
853 | |||
854 | public function gather_labels($beans){ |
||
855 | $result = $this->redbean->gatherLabels($beans); |
||
856 | return ($result) ? $result : false; |
||
857 | } |
||
858 | |||
859 | public function enum($enum){ |
||
860 | $result = $this->redbean->enum($enum); |
||
861 | return ($result) ? $result : false; |
||
862 | } |
||
863 | |||
864 | public function tag($bean, $tagList){ |
||
865 | $result = $this->redbean->tag($bean, $tagList); |
||
866 | return ($result) ? $result : false; |
||
867 | } |
||
868 | |||
869 | public function add_tag($bean, $tagList){ |
||
870 | $result = $this->redbean->addTags($bean, $tagList); |
||
871 | return ($result) ? $result : false; |
||
872 | } |
||
873 | |||
874 | public function tagged($beanType,$tagList,$sql='',$bindings=array()){ |
||
875 | $result = $this->redbean->addTags($beanType,$tagList,$sql,$bindings); |
||
876 | return ($result) ? $result : false; |
||
877 | } |
||
878 | |||
879 | public function untag($bean,$tagList){ |
||
880 | $result = $this->redbean->untag($bean,$tagList); |
||
881 | return ($result) ? $result : false; |
||
882 | } |
||
883 | |||
884 | public function tagged_all($beanType,$tagList,$sql='',$bindings=array()){ |
||
885 | $result = $this->redbean->taggedAll($beanType,$tagList,$sql,$bindings); |
||
886 | return ($result) ? $result : false; |
||
887 | } |
||
888 | |||
889 | public function count_tagged_all($beanType,$tagList,$sql='',$bindings=array()){ |
||
890 | $result = $this->redbean->countTaggedAll($beanType,$tagList,$sql,$bindings); |
||
891 | return ($result) ? $result : false; |
||
892 | } |
||
893 | |||
894 | public function count_tagged($beanType,$tagList,$sql='',$bindings=array()){ |
||
895 | $result = $this->redbean->countTagged($beanType,$tagList,$sql,$bindings); |
||
896 | return ($result) ? $result : false; |
||
897 | } |
||
898 | |||
899 | public function has_tag($bean,$tags,$all=FALSE){ |
||
900 | $result = $this->redbean->hasTag($bean,$tags,$all); |
||
901 | return ($result) ? $result : false; |
||
902 | } |
||
903 | |||
904 | /*Import and Export*/ |
||
905 | public function import($array, $selection = FALSE, $notrim = FALSE){ |
||
906 | $result = $this->redbean->import($array,$selection,$notrim); |
||
907 | return ($result) ? $result : false; |
||
908 | } |
||
909 | |||
910 | public function import_row($row){ |
||
911 | $result = $this->redbean->importRow($row); |
||
912 | return ($result) ? $result : false; |
||
913 | } |
||
914 | |||
915 | public function export($meta = FALSE, $parents = FALSE, $onlyMe = FALSE, $filters = array()){ |
||
916 | $result = $this->redbean->export($meta,$parents,$onlyMe,$filters); |
||
917 | return ($result) ? $result : false; |
||
918 | } |
||
919 | |||
920 | public function export_all($beans, $parents = FALSE, $filters = array()){ |
||
921 | $result = $this->redbean->exportAll($beans,$parents,$filters); |
||
922 | return ($result) ? $result : false; |
||
923 | } |
||
924 | |||
925 | public function import_from($sourceBean){ |
||
926 | $result = $this->redbean->importFrom($sourceBean); |
||
927 | return ($result) ? $result : false; |
||
928 | } |
||
929 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.