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