Can I get some pointers, critiques and/or comments on the following model? (p.s. performance seems great... tested all methods up to 10,000 records)
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class o7th_Model extends CI_Model {
private $msg;
private $last_id;
private $full_qry_count;
public function __construct(){
parent::__construct();
$this->load->database();
$this->load->library('form_validation');
$this->load->library('pagination');
}
// Setup a list assoc array to return
/*
* USAGE - the only array parameter required is the 'table_name'
self::qlist(array('select'=>'FIELDS', --- should be a comma seperate string of field names
'where'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'or_where'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'where_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'or_where_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'where_not_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'or_where_not_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'like'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'or_like'array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'not_like'array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'or_not_like'array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'group_by'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'distinct'=>'TRUE/FALSE/NULL', --- TRUE enables SELECT DISTINCT, FALSE/NULL doesnt bother adding it
'having'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'or_having'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'order_by'=>array(array('field'=>'FIELD_NAME', 'direction'=>'ASC/DESC'),), --- can have as many of these field/direction arrays as you need, direction is optional
'limit'=>array(array('limit'=>'NUMBER_TO_LIMIT_RESULTS', 'offset'=>'NUMBER_TO_LIMIT_RESULTS')),
'join'=>array(array('table'=>'TABLE_NAME_TO_JOIN', 'on'=>'EX: a.field1 = b.field2', 'direction'=>'left/right/outer/inner/left outer/right outer'),), --- can have as many of these table/on/direction arrays as you need
'pagination'=>array('per_page'=>'', 'page_num'=>''), --- do not use this with limit... you will get undesirable results
'table_name'=>'TABLE_NAME')); --- REQUIRED!!!
*/
public function qlist(){
$tArgs = func_get_args();
$tbl = self::prepArgs(1, $tArgs);
$qry = $this->db->get($tbl);
if($qry){
$rs = $qry->result_array();
$this->full_qry_count = count($rs);
if(array_key_exists('pagination', $tArgs[0])){
$rs = array_slice($rs, $tArgs[0]['pagination']['page_num'], $tArgs[0]['pagination']['per_page']);
}
}else{
$rs = null;
}
return $rs;
}
// setup a return assoc array details record, only returns 1 record
/*
* USAGE - the only array parameter required is the 'table_name'
self::qdetails(array('select'=>'FIELDS', --- should be a comma seperate string of field names
'where'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'or_where'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'where_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'or_where_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'where_not_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'or_where_not_in'=>array(array('field'=>'FIELD_NAME', 'value'=>array('VAL1', 'VAL2', etc...)),), --- can have as many of these field/value arrays as you need, value needs to be an array
'like'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'or_like'array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'not_like'array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'or_not_like'array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE', 'wildcard'=>'before/after/both/none'),), --- can have as many of these field/value arrays as you need, wildcard is optional
'group_by'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'distinct'=>'TRUE/FALSE/NULL', --- TRUE enables SELECT DISTINCT, FALSE/NULL doesnt bother adding it
'having'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'or_having'=>array(array('field'=>'FIELD_NAME', 'value'=>'FIELD_VALUE'),), --- can have as many of these field/value arrays as you need
'order_by'=>array(array('field'=>'FIELD_NAME', 'direction'=>'ASC/DESC'),), --- can have as many of these field/direction arrays as you need, direction is optional
'limit'=>array(array('limit'=>'NUMBER_TO_LIMIT_RESULTS', 'offset'=>'NUMBER_TO_LIMIT_RESULTS')),
'join'=>array(array('table'=>'TABLE_NAME_TO_JOIN', 'on'=>'EX: a.field1 = b.field2', 'direction'=>'left/right/outer/inner/left outer/right outer'),), --- can have as many of these table/on/direction arrays as you need
'table_name'=>'TABLE_NAME')); --- REQUIRED!!!
*/
public function qdetails(){
$tbl = self::prepArgs(1, func_get_args());
$qry = $this->db->get($tbl);
return ($qry) ? $qry->row_array() : null;
}
public function qinsert(){
return self::prepArgs(2, func_get_args());
}
public function qedit(){
return self::prepArgs(3, func_get_args());
}
// setup db delete, return BOOLEAN
public function qdelete(){
$tbl = self::prepArgs(4, func_get_args());
$this->db->delete('Storage_Users');
if($this->db->affected_rows() > 0){
return TRUE;
}else{
$this->msg = 'There was an issue removing that record.<br />' . $this->db->_error_message();
return FALSE;
}
}
// get the last inserted id - only valid on inserts
public function last_insert_id(){
return $this->last_id;
}
// return a message if any of the returns above are invalid/false/errored out
public function message(){
return $this->msg;
}
// return a number of records based on the query run/ only valid on the selects
public function fullrecordcount(){
return $this->full_qry_count;
}
// return the pagination links
public function paginator($base_url, $per_page, $total_rows, $num_links, $uri_segment, $aclass = null){
$config['base_url'] = $base_url;
$config['per_page'] = $per_page;
$config['total_rows'] = $total_rows;
$config['num_links'] = $num_links;
$config['first_link'] = '<span class="fa fa-angle-double-left page_num"></span>';
$config['last_link'] = '<span class="fa fa-angle-double-right page_num"></span>';
$config['cur_tag_open'] = '<span class="page_num bold">';
$config['cur_tag_close'] = '</span>';
$config['next_link'] = '<span class="fa fa-angle-right page_num"></span>';
$config['prev_link'] = '<span class="fa fa-angle-left page_num"></span>';
$config['uri_segment'] = $uri_segment;
$config['num_tag_open'] = '<span class="page_num">';
$config['num_tag_close'] = '</span>';
if($aclass != null){
$config['anchor_class'] = 'class="' . $aclass . '" ';
}
$this->pagination->initialize($config);
return $this->pagination->create_links();
}
// setup all possible arguments for all of the above, return name of the table from the arguments
private function prepArgs($which, $args){
if($args){
try{
switch($which){
case 1: // select
return self::setupSelect($args);
break;
case 2: // insert
return self::setupInsert($args);
break;
case 3: // update
return self::setupEdit($args);
break;
case 4: // delete
return self::setupDelete($args);
break;
}
}catch(Exception $ex){
$this->$msg .= $ex->getMessage();
}
}else{
$this->$msg .= 'You have not passed in any arguments to your query, please have a look over your code.';
}
}
// setup our edit
private function setupEdit($args){
// where clause(s)
if(array_key_exists('where', $args[0])){
$w = $args[0]['where'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where clause(s)
if(array_key_exists('or_where', $args[0])){
$w = $args[0]['or_where'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// where_in clause(s)
if(array_key_exists('where_in', $args[0])){
$w = $args[0]['where_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where_in clause(s)
if(array_key_exists('or_where_in', $args[0])){
$w = $args[0]['or_where_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// where_not_in clause(s)
if(array_key_exists('where_not_in', $args[0])){
$w = $args[0]['where_not_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where_not_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where_not_in clause(s)
if(array_key_exists('or_where_not_in', $args[0])){
$w = $args[0]['or_where_not_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where_not_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// like clause(s)
if(array_key_exists('like', $args[0])){
$l = $args[0]['like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// or_like clause(s)
if(array_key_exists('or_like', $args[0])){
$l = $args[0]['or_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->or_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// not_like clause(s)
if(array_key_exists('not_like', $args[0])){
$l = $args[0]['not_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->not_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// or_not_like clause(s)
if(array_key_exists('or_not_like', $args[0])){
$l = $args[0]['or_not_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->or_not_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// group_by clause(s)
if(array_key_exists('group_by', $args[0])){
$g = $args[0]['group_by'];
$gCt = count($g);
for($gg = 0; $gg < $gCt; ++$gg){
if($g[$gg]['value']){
$this->db->group_by($g[$gg]['field'], $g[$gg]['value']);
}
}
unset($g);
}
// having clause(s)
if(array_key_exists('having', $args[0])){
$h = $args[0]['having'];
$hCt = count($h);
for($hh = 0; $hh < $hCt; ++$hh){
if($h[$hh]['value']){
$this->db->having($h[$hh]['field'], $h[$hh]['value']);
}
}
unset($h);
}
// or_having clause(s)
if(array_key_exists('or_having', $args[0])){
$h = $args[0]['or_having'];
$hCt = count($h);
for($hh = 0; $hh < $hCt; ++$hh){
if($h[$hh]['value']){
$this->db->or_having($h[$hh]['field'], $h[$hh]['value']);
}
}
unset($h);
}
// join clause(s)
if(array_key_exists('join', $args[0])){
$j = $args[0]['join'];
$jCt = count($j);
for($jj = 0; $jj < $jCt; ++$jj){
$this->db->join($j[$jj]['table'], $j[$jj]['on'], $j[$jj]['direction']);
}
unset($j);
}
$data = array();
$tname = '';
$valid = TRUE;
// array of data to insert: required
if(array_key_exists('update', $args[0])){
$data = $args[0]['update'];
}else{
$valid = FALSE;
$this->$msg .= 'You need to specify field/value pairs of data to update.';
}
// table name: required
if(array_key_exists('table_name', $args[0])){
$tname = $args[0]['table_name'];
}else{
$valid = FALSE;
$this->$msg .= 'You need to specify a table name to update.';
}
// setup our validations
if(array_key_exists('validations', $args[0])){
$v = $args[0]['validations'];
$vCt = count($v);
for($vv = 0; $vv < $vCt; ++$vv){
$this->form_validation->set_rules($v[$vv]['field'], $v[$vv]['label'], $v[$vv]['validation']);
}
if ($this->form_validation->run() === FALSE){
$valid = FALSE;
$this->$msg .= validation_errors();
}
}
if($valid){
$this->db->update($tname, $data);
$a = ($this->db->affected_rows() > 0);
if(!$a){
$this->$msg .= $this->db->_error_message();
return FALSE;
}else{
return TRUE;
}
}else{
return $valid;
}
}
// setup our delete
private function setupDelete($args){
// where clause(s)
if(array_key_exists('where', $args[0])){
$w = $args[0]['where'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where clause(s)
if(array_key_exists('or_where', $args[0])){
$w = $args[0]['or_where'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// where_in clause(s)
if(array_key_exists('where_in', $args[0])){
$w = $args[0]['where_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where_in clause(s)
if(array_key_exists('or_where_in', $args[0])){
$w = $args[0]['or_where_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// where_not_in clause(s)
if(array_key_exists('where_not_in', $args[0])){
$w = $args[0]['where_not_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where_not_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where_not_in clause(s)
if(array_key_exists('or_where_not_in', $args[0])){
$w = $args[0]['or_where_not_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where_not_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// like clause(s)
if(array_key_exists('like', $args[0])){
$l = $args[0]['like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// or_like clause(s)
if(array_key_exists('or_like', $args[0])){
$l = $args[0]['or_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->or_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// not_like clause(s)
if(array_key_exists('not_like', $args[0])){
$l = $args[0]['not_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->not_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// or_not_like clause(s)
if(array_key_exists('or_not_like', $args[0])){
$l = $args[0]['or_not_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->or_not_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// group_by clause(s)
if(array_key_exists('group_by', $args[0])){
$g = $args[0]['group_by'];
$gCt = count($g);
for($gg = 0; $gg < $gCt; ++$gg){
if($g[$gg]['value']){
$this->db->group_by($g[$gg]['field'], $g[$gg]['value']);
}
}
unset($g);
}
// having clause(s)
if(array_key_exists('having', $args[0])){
$h = $args[0]['having'];
$hCt = count($h);
for($hh = 0; $hh < $hCt; ++$hh){
if($h[$hh]['value']){
$this->db->having($h[$hh]['field'], $h[$hh]['value']);
}
}
unset($h);
}
// or_having clause(s)
if(array_key_exists('or_having', $args[0])){
$h = $args[0]['or_having'];
$hCt = count($h);
for($hh = 0; $hh < $hCt; ++$hh){
if($h[$hh]['value']){
$this->db->or_having($h[$hh]['field'], $h[$hh]['value']);
}
}
unset($h);
}
// join clause(s)
if(array_key_exists('join', $args[0])){
$j = $args[0]['join'];
$jCt = count($j);
for($jj = 0; $jj < $jCt; ++$jj){
$this->db->join($j[$jj]['table'], $j[$jj]['on'], $j[$jj]['direction']);
}
unset($j);
}
// table name: required
if(array_key_exists('table_name', $args[0])){
return $args[0]['table_name'];
}
}
// setup(and run) our insert
private function setupInsert($args){
$data = array();
$tname = '';
$valid = TRUE;
// array of data to insert: required
if(array_key_exists('insert', $args[0])){
$data = $args[0]['insert'];
}else{
$valid = FALSE;
$this->$msg .= 'You need to specify field/value pairs of data to insert.';
}
// table name: required
if(array_key_exists('table_name', $args[0])){
$tname = $args[0]['table_name'];
}else{
$valid = FALSE;
$this->$msg .= 'You need to specify a table name to insert data into.';
}
// setup our validations
if(array_key_exists('validations', $args[0])){
$v = $args[0]['validations'];
$vCt = count($v);
for($vv = 0; $vv < $vCt; ++$vv){
$this->form_validation->set_rules($v[$vv]['field'], $v[$vv]['label'], $v[$vv]['validation']);
}
if ($this->form_validation->run() === FALSE){
$valid = FALSE;
$this->$msg .= validation_errors();
}
}
if($valid){
$this->db->insert($tname, $data);
$a = ($this->db->affected_rows() > 0);
if(!$a){
$this->$msg .= $this->db->_error_message();
return FALSE;
}else{
$this->last_id = $this->db->insert_id();
return TRUE;
}
}else{
return $valid;
}
}
// setup our select
private function setupSelect($args){
// select field names
if(array_key_exists('select', $args[0])){
$this->db->select($args[0]['select']);
}
// where clause(s)
if(array_key_exists('where', $args[0])){
$w = $args[0]['where'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where clause(s)
if(array_key_exists('or_where', $args[0])){
$w = $args[0]['or_where'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// where_in clause(s)
if(array_key_exists('where_in', $args[0])){
$w = $args[0]['where_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where_in clause(s)
if(array_key_exists('or_where_in', $args[0])){
$w = $args[0]['or_where_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// where_not_in clause(s)
if(array_key_exists('where_not_in', $args[0])){
$w = $args[0]['where_not_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->where_not_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// or_where_not_in clause(s)
if(array_key_exists('or_where_not_in', $args[0])){
$w = $args[0]['or_where_not_in'];
$wCt = count($w);
for($ww = 0; $ww < $wCt; ++$ww){
if($w[$ww]['value']){
$this->db->or_where_not_in($w[$ww]['field'], $w[$ww]['value']);
}
}
unset($w);
}
// like clause(s)
if(array_key_exists('like', $args[0])){
$l = $args[0]['like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// or_like clause(s)
if(array_key_exists('or_like', $args[0])){
$l = $args[0]['or_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->or_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// not_like clause(s)
if(array_key_exists('not_like', $args[0])){
$l = $args[0]['not_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->not_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// or_not_like clause(s)
if(array_key_exists('or_not_like', $args[0])){
$l = $args[0]['or_not_like'];
$lCt = count($l);
for($ll = 0; $ll < $lCt; ++$ll){
if($l[$ll]['value']){
$this->db->or_not_like($l[$ll]['field'], $l[$ll]['value'], (isset($l[$ll]['wildcard'])) ? $l[$ll]['wildcard'] : null);
}
}
unset($l);
}
// group_by clause(s)
if(array_key_exists('group_by', $args[0])){
$g = $args[0]['group_by'];
$gCt = count($g);
for($gg = 0; $gg < $gCt; ++$gg){
if($g[$gg]['value']){
$this->db->group_by($g[$gg]['field'], $g[$gg]['value']);
}
}
unset($g);
}
// distinct flag
if(array_key_exists('distinct', $args[0]) && $args[0]['distinct'] === TRUE){
$this->db->distinct();
}
// having clause(s)
if(array_key_exists('having', $args[0])){
$h = $args[0]['having'];
$hCt = count($h);
for($hh = 0; $hh < $hCt; ++$hh){
if($h[$hh]['value']){
$this->db->having($h[$hh]['field'], $h[$hh]['value']);
}
}
unset($h);
}
// or_having clause(s)
if(array_key_exists('or_having', $args[0])){
$h = $args[0]['or_having'];
$hCt = count($h);
for($hh = 0; $hh < $hCt; ++$hh){
if($h[$hh]['value']){
$this->db->or_having($h[$hh]['field'], $h[$hh]['value']);
}
}
unset($h);
}
// order_by clause(s)
if(array_key_exists('order_by', $args[0])){
$o = $args[0]['order_by'];
$oCt = count($o);
for($oo = 0; $oo < $oCt; ++$oo){
if($o[$oo]['direction']){
$this->db->order_by($o[$oo]['field'], $o[$oo]['direction']);
}else{
$this->db->order_by($o[$oo]['field']);
}
}
unset($o);
}
// join clause(s)
if(array_key_exists('join', $args[0])){
$j = $args[0]['join'];
$jCt = count($j);
for($jj = 0; $jj < $jCt; ++$jj){
$this->db->join($j[$jj]['table'], $j[$jj]['on'], $j[$jj]['direction']);
}
unset($j);
}
// limit
if(array_key_exists('limit', $args[0])){
$this->db->limit($args[0]['limit']['limit'], $args[0]['limit']['offset']);
}
// table name: required
if(array_key_exists('table_name', $args[0])){
return $args[0]['table_name'];
}
}
}
?>
error_reporting(-1)
), you're calling non-static methods statically all over the place. Don't. Also, if you want code to be reviewed, please follow the (coding-style conventions)[php-fig.org] your framework subscribes to. It makes the reviewer's life easier not having to get accustomed to your indentation-style. Oh, and 10,000 records is all fine and dandy, but I'd test my code up to 10,000,000 records before making any assumptions as far as performance goes. I'd also use apache benchmark (ab -c 100 -n 10000
) \$\endgroup\$