private static function runQueryWithView($query, $fields, $printArray) { $_SESSION['tableData'] = array(); $exec_time_row = array(); $records = ''; try { // turn on query profiling Flight::get('db')->query('SET profiling = 1;'); $stmt = Flight::get('db')->query($query); // find out time above query was ran for $exec_time_result = Flight::get('db')->query('SELECT query_id, SUM(duration) FROM information_schema.profiling GROUP BY query_id ORDER BY query_id DESC LIMIT 1;'); $exec_time_row = $exec_time_result->fetchAll(PDO::FETCH_NUM); // run query and fetch array $data = $stmt->fetchAll(PDO::FETCH_ASSOC); // store table fields/columns + data rows in session for exporting later $_SESSION['tableData'] = array_merge($fields, $data); $records = Presenter::listTableData($data); } catch (PDOException $e) { setFlashMessage('Error: ' . $e->getMessage()); } Flight::render('table', array('title' => Flight::get('lastSegment'), 'icon' => self::$icon, 'table_data' => $records, 'fields' => getOptions($fields), 'query' => SqlFormatter::format($query), 'printArray' => $printArray, 'timetaken' => $exec_time_row[0][1])); }