public function FetchRows($params, &$meta = null) { //parse params **not finished more validation and switches to come $selectItems = $params['select_items']; $where = !empty($params['where_items']) ? $params['where_items'] : null; $table = $params['from']; $isWhereString = isset($params['where_items']) && is_array($params['where_items']) && count($params['where_items']) > 0; /////////////////////////////////////////////////////////// //BUILD QUERY ///////////////////////////////////////////// $SQL = ''; //BUILD SELCET ============================================ $selectString = 'SELECT ' . join(", ", (array) $selectItems); //BUILD WHERE ============================================== $fromString = 'FROM ' . $table; //BUILD WHERE ============================================== //$isWhereString //$where $whereString = ''; if (!empty($where) && is_array($where)) { $whereBindParams = array(); $whereString = $this->buildWhere($isWhereString, $whereBindParams, $where); } else { $whereString = 'WHERE 1 = 1'; } //COMPILE STATEMENT =========================================== $SQL = $selectString . ' ' . $fromString . ' ' . $whereString; //SERVER::dump($SQL); /////////////////////////////////////////////////////////// <-- split seperate functions //RUN QUERY /////////////////////////////////////////////// <-- might need to accept other params from order by or group //PREPAIR STATEMENT ========================================= $theStatement = $this->connection->prepare($SQL); if (!empty($whereBindParams)) { call_user_func_array(array($theStatement, 'bind_param'), $whereBindParams); // replace $whereBindParams with list of fields from emta data of statement } //BIND RESULT ================================================ $bind_result = array(); if (!empty($selectItems) && is_array($selectItems)) { DBI::bindResult($theStatement, $selectItems, $bind_result); // modify to expect from statement } //EXECUTE FETCH =========================================== $theStatement->execute(); $result = array(); while ($theStatement->fetch()) { $aRow = array(); //clone values of referenced array foreach ($bind_result as $key => $value) { $aRow[$key] = $value; } $result[] = $aRow; } $theStatement->close(); return $result; }