init_class('CI_DB_export', 'dbexport'); // ------------------------------------------------------------------------ /** * DB Exporting Class * * @category Database * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_export { /** * Constructor. Simply calls the log function */ function CI_DB_export() { log_message('debug', "Database Export Class Initialized"); } /** * Generate CVS from a query result object * * @access public * @param object The query result object * @param string The delimiter - tab by default * @param string The newline character - \n by default * @return string */ function generate_cvs($query, $delim = "\t", $newline = "\n") { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { show_error('You must submit a valid result object'); } $out = ''; // First generate the headings from the table column names foreach ($query->field_names() as $name) { $out .= $name.$delim; } $out .= $newline; // Next blast through the result array and build out the rows foreach ($query->result_array() as $row) { foreach ($row as $item) { $out .= $item.$delim; } $out .= $newline; } return $out; } // -------------------------------------------------------------------- } ?>