blob: 14e7af68b97081a0d567e0a8c9bd25373afd9947 [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
admine79dc712006-09-26 03:52:45 +000016
17
18// INITIALIZE THE CLASS ---------------------------------------------------
19
20$obj =& get_instance();
admin7981a9a2006-09-26 07:52:09 +000021$obj->init_class('CI_DB_export', 'dbexport');
admine79dc712006-09-26 03:52:45 +000022
admin1716d582006-09-24 20:15:03 +000023// ------------------------------------------------------------------------
24
25/**
26 * DB Exporting Class
27 *
28 * @category Database
29 * @author Rick Ellis
30 * @link http://www.codeigniter.com/user_guide/database/
31 */
32class CI_DB_export {
admin910d8622006-09-26 02:09:05 +000033
34
35 function CI_DB_export()
36 {
37 log_message('debug', "Database Export Class Initialized");
38 }
39
admin1716d582006-09-24 20:15:03 +000040 /**
admin910d8622006-09-26 02:09:05 +000041 * Generate CVS
admin1716d582006-09-24 20:15:03 +000042 *
43 * @access public
44 * @return integer
45 */
admin910d8622006-09-26 02:09:05 +000046 function generate_cvs($query, $delim = "\t", $newline = "\n")
admin1716d582006-09-24 20:15:03 +000047 {
admin910d8622006-09-26 02:09:05 +000048 if ( ! is_object($query) OR ! method_exists($query, 'field_names'))
49 {
50 show_error('You must submit a valid result object');
51 }
52
53 $out = '';
54 foreach ($query->field_names() as $name)
55 {
56 $out .= $name.$delim;
57 }
58
59 $out .= $newline;
60
61 foreach ($query->result_array() as $row)
62 {
63 foreach ($row as $item)
64 {
65 $out .= $item.$delim;
66 }
67
68 $out .= $newline;
69 }
70
71
72 return $out;
admin1716d582006-09-24 20:15:03 +000073 }
74
75 // --------------------------------------------------------------------
76
admin910d8622006-09-26 02:09:05 +000077
admin1716d582006-09-24 20:15:03 +000078}
79
80?>