admin | 1716d58 | 2006-09-24 20:15:03 +0000 | [diff] [blame] | 1 | <?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 | */ |
| 25 | class CI_DB_export { |
admin | 910d862 | 2006-09-26 02:09:05 +0000 | [diff] [blame] | 26 | |
| 27 | |
| 28 | function CI_DB_export() |
| 29 | { |
| 30 | log_message('debug', "Database Export Class Initialized"); |
| 31 | } |
| 32 | |
admin | 1716d58 | 2006-09-24 20:15:03 +0000 | [diff] [blame] | 33 | /** |
admin | 910d862 | 2006-09-26 02:09:05 +0000 | [diff] [blame] | 34 | * Generate CVS |
admin | 1716d58 | 2006-09-24 20:15:03 +0000 | [diff] [blame] | 35 | * |
| 36 | * @access public |
| 37 | * @return integer |
| 38 | */ |
admin | 910d862 | 2006-09-26 02:09:05 +0000 | [diff] [blame] | 39 | function generate_cvs($query, $delim = "\t", $newline = "\n") |
admin | 1716d58 | 2006-09-24 20:15:03 +0000 | [diff] [blame] | 40 | { |
admin | 910d862 | 2006-09-26 02:09:05 +0000 | [diff] [blame] | 41 | 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; |
admin | 1716d58 | 2006-09-24 20:15:03 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // -------------------------------------------------------------------- |
| 69 | |
admin | 910d862 | 2006-09-26 02:09:05 +0000 | [diff] [blame] | 70 | |
admin | 1716d58 | 2006-09-24 20:15:03 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | ?> |