blob: 1e94c6c9779f0aba15c37b3cdde1018b4475c28b [file] [log] [blame]
admin1716d582006-09-24 20:15:03 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * DB Exporting Class
20 *
21 * @category Database
22 * @author Rick Ellis
23 * @link http://www.codeigniter.com/user_guide/database/
24 */
25class CI_DB_export {
admin910d8622006-09-26 02:09:05 +000026
27
28 function CI_DB_export()
29 {
30 log_message('debug', "Database Export Class Initialized");
31 }
32
admin1716d582006-09-24 20:15:03 +000033 /**
admin910d8622006-09-26 02:09:05 +000034 * Generate CVS
admin1716d582006-09-24 20:15:03 +000035 *
36 * @access public
37 * @return integer
38 */
admin910d8622006-09-26 02:09:05 +000039 function generate_cvs($query, $delim = "\t", $newline = "\n")
admin1716d582006-09-24 20:15:03 +000040 {
admin910d8622006-09-26 02:09:05 +000041 if ( ! is_object($query) OR ! method_exists($query, 'field_names'))
42 {
43 show_error('You must submit a valid result object');
44 }
45
46 $out = '';
47 foreach ($query->field_names() as $name)
48 {
49 $out .= $name.$delim;
50 }
51
52 $out .= $newline;
53
54 foreach ($query->result_array() as $row)
55 {
56 foreach ($row as $item)
57 {
58 $out .= $item.$delim;
59 }
60
61 $out .= $newline;
62 }
63
64
65 return $out;
admin1716d582006-09-24 20:15:03 +000066 }
67
68 // --------------------------------------------------------------------
69
admin910d8622006-09-26 02:09:05 +000070
admin1716d582006-09-24 20:15:03 +000071}
72
73?>