blob: 9803307ed31bfb1711a62efbfeee2ce5c9129472 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
Derek Jonesf4a4bd82011-10-20 12:18:42 -05003 * CodeIgniter
Derek Allard2067d1a2008-11-13 22:59:24 +00004 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev24276a32012-01-08 02:44:38 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev24276a32012-01-08 02:44:38 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * Database Utility Class
31 *
32 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050033 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000034 * @link http://codeigniter.com/user_guide/database/
35 */
Andrey Andreeveaa60c72012-11-06 01:11:22 +020036abstract class CI_DB_utility {
Derek Allard2067d1a2008-11-13 22:59:24 +000037
Andrey Andreevae85eb42012-11-02 01:42:31 +020038 /**
39 * Database object
40 *
41 * @var object
42 */
Andrey Andreeveaa60c72012-11-06 01:11:22 +020043 protected $db;
Derek Allard2067d1a2008-11-13 22:59:24 +000044
Andrey Andreevae85eb42012-11-02 01:42:31 +020045 // --------------------------------------------------------------------
46
47 /**
Andrey Andreevc98e93a2012-11-02 02:04:59 +020048 * List databases statement
49 *
50 * @var string
51 */
Andrey Andreeva24e52e2012-11-02 03:54:12 +020052 protected $_list_databases = FALSE;
Andrey Andreevc98e93a2012-11-02 02:04:59 +020053
54 /**
Andrey Andreevae85eb42012-11-02 01:42:31 +020055 * OPTIMIZE TABLE statement
56 *
Andrey Andreevc98e93a2012-11-02 02:04:59 +020057 * @var string
Andrey Andreevae85eb42012-11-02 01:42:31 +020058 */
Andrey Andreevb457a402012-04-09 16:11:56 +030059 protected $_optimize_table = FALSE;
Andrey Andreevae85eb42012-11-02 01:42:31 +020060
61 /**
62 * REPAIR TABLE statement
63 *
Andrey Andreevc98e93a2012-11-02 02:04:59 +020064 * @var string
Andrey Andreevae85eb42012-11-02 01:42:31 +020065 */
Andrey Andreevb457a402012-04-09 16:11:56 +030066 protected $_repair_table = FALSE;
67
Andrey Andreevae85eb42012-11-02 01:42:31 +020068 // --------------------------------------------------------------------
69
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030070 /**
Andrey Andreevc98e93a2012-11-02 02:04:59 +020071 * Class constructor
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030072 *
Andrey Andreeveaa60c72012-11-06 01:11:22 +020073 * @param object &$db Database object
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030074 * @return void
75 */
Andrey Andreeveaa60c72012-11-06 01:11:22 +020076 public function __construct(&$db)
Derek Allard2067d1a2008-11-13 22:59:24 +000077 {
Andrey Andreeveaa60c72012-11-06 01:11:22 +020078 $this->db =& $db;
Andrey Andreev24276a32012-01-08 02:44:38 +020079 log_message('debug', 'Database Utility Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000080 }
81
82 // --------------------------------------------------------------------
83
84 /**
85 * List databases
86 *
Andrey Andreevb457a402012-04-09 16:11:56 +030087 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +000088 */
Andrey Andreev24276a32012-01-08 02:44:38 +020089 public function list_databases()
Barry Mienydd671972010-10-04 16:33:58 +020090 {
Derek Allard2067d1a2008-11-13 22:59:24 +000091 // Is there a cached result?
Andrey Andreev5d281762012-06-11 22:05:40 +030092 if (isset($this->db->data_cache['db_names']))
Derek Allard2067d1a2008-11-13 22:59:24 +000093 {
Andrey Andreev5d281762012-06-11 22:05:40 +030094 return $this->db->data_cache['db_names'];
Derek Allard2067d1a2008-11-13 22:59:24 +000095 }
Andrey Andreevb457a402012-04-09 16:11:56 +030096 elseif ($this->_list_databases === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +000097 {
Andrey Andreev8d3afde2012-11-06 12:53:47 +020098 return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000099 }
Barry Mienydd671972010-10-04 16:33:58 +0200100
Andrey Andreev5d281762012-06-11 22:05:40 +0300101 $this->db->data_cache['db_names'] = array();
Andrey Andreevb457a402012-04-09 16:11:56 +0300102
103 $query = $this->db->query($this->_list_databases);
104 if ($query === FALSE)
105 {
Andrey Andreev5d281762012-06-11 22:05:40 +0300106 return $this->db->data_cache['db_names'];
Andrey Andreevb457a402012-04-09 16:11:56 +0300107 }
108
Andrey Andreev9e945762012-11-13 01:08:34 +0200109 for ($i = 0, $query = $query->result_array(), $c = count($query); $i < $c; $i++)
Andrey Andreevb457a402012-04-09 16:11:56 +0300110 {
Andrey Andreev9e945762012-11-13 01:08:34 +0200111 $this->db->data_cache['db_names'][] = current($query[$i]);
Andrey Andreevb457a402012-04-09 16:11:56 +0300112 }
113
Andrey Andreev5d281762012-06-11 22:05:40 +0300114 return $this->db->data_cache['db_names'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 }
116
117 // --------------------------------------------------------------------
118
119 /**
Derek Allarde7f03252010-02-04 16:47:01 +0000120 * Determine if a particular database exists
121 *
Andrey Andreevae85eb42012-11-02 01:42:31 +0200122 * @param string $database_name
Andrey Andreevb457a402012-04-09 16:11:56 +0300123 * @return bool
Derek Allarde7f03252010-02-04 16:47:01 +0000124 */
Andrey Andreev24276a32012-01-08 02:44:38 +0200125 public function database_exists($database_name)
Derek Allard62396232010-02-04 17:45:47 +0000126 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300127 return in_array($database_name, $this->list_databases());
Derek Allarde7f03252010-02-04 16:47:01 +0000128 }
129
130 // --------------------------------------------------------------------
131
132 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 * Optimize Table
134 *
Andrey Andreevae85eb42012-11-02 01:42:31 +0200135 * @param string $table_name
Andrey Andreevb457a402012-04-09 16:11:56 +0300136 * @return mixed
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 */
Andrey Andreev24276a32012-01-08 02:44:38 +0200138 public function optimize_table($table_name)
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300140 if ($this->_optimize_table === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 {
Andrey Andreev8d3afde2012-11-06 12:53:47 +0200142 return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 }
Barry Mienydd671972010-10-04 16:33:58 +0200144
Andrey Andreevb457a402012-04-09 16:11:56 +0300145 $query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
146 if ($query !== FALSE)
147 {
148 $query = $query->result_array();
Dimitar34cadee2012-11-24 13:13:07 +0200149 return current($query);
Andrey Andreevb457a402012-04-09 16:11:56 +0300150 }
Barry Mienydd671972010-10-04 16:33:58 +0200151
Andrey Andreevb457a402012-04-09 16:11:56 +0300152 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 }
154
155 // --------------------------------------------------------------------
156
157 /**
158 * Optimize Database
159 *
Andrey Andreevb457a402012-04-09 16:11:56 +0300160 * @return mixed
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 */
Andrey Andreev24276a32012-01-08 02:44:38 +0200162 public function optimize_database()
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300164 if ($this->_optimize_table === FALSE)
165 {
Andrey Andreev8d3afde2012-11-06 12:53:47 +0200166 return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
Andrey Andreevb457a402012-04-09 16:11:56 +0300167 }
168
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 $result = array();
170 foreach ($this->db->list_tables() as $table_name)
171 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300172 $res = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
173 if (is_bool($res))
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300175 return $res;
Derek Allard2067d1a2008-11-13 22:59:24 +0000176 }
Barry Mienydd671972010-10-04 16:33:58 +0200177
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 // Build the result array...
Andrey Andreevb457a402012-04-09 16:11:56 +0300179 $res = $res->result_array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 $res = current($res);
181 $key = str_replace($this->db->database.'.', '', current($res));
182 $keys = array_keys($res);
183 unset($res[$keys[0]]);
Barry Mienydd671972010-10-04 16:33:58 +0200184
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 $result[$key] = $res;
186 }
187
188 return $result;
189 }
190
191 // --------------------------------------------------------------------
192
193 /**
194 * Repair Table
195 *
Andrey Andreevae85eb42012-11-02 01:42:31 +0200196 * @param string $table_name
Andrey Andreevb457a402012-04-09 16:11:56 +0300197 * @return mixed
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 */
Andrey Andreev24276a32012-01-08 02:44:38 +0200199 public function repair_table($table_name)
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300201 if ($this->_repair_table === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 {
Andrey Andreev8d3afde2012-11-06 12:53:47 +0200203 return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 }
Barry Mienydd671972010-10-04 16:33:58 +0200205
Andrey Andreevb457a402012-04-09 16:11:56 +0300206 $query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name)));
207 if (is_bool($query))
208 {
209 return $query;
210 }
Barry Mienydd671972010-10-04 16:33:58 +0200211
Andrey Andreevb457a402012-04-09 16:11:56 +0300212 $query = $query->result_array();
213 return current($query);
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 }
Barry Mienydd671972010-10-04 16:33:58 +0200215
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 // --------------------------------------------------------------------
217
218 /**
219 * Generate CSV from a query result object
220 *
Andrey Andreevae85eb42012-11-02 01:42:31 +0200221 * @param object $query Query result object
222 * @param string $delim Delimiter (default: ,)
223 * @param string $newline Newline character (default: \n)
224 * @param string $enclosure Enclosure (default: ")
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 * @return string
226 */
Andrey Andreev24276a32012-01-08 02:44:38 +0200227 public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
Derek Allard2067d1a2008-11-13 22:59:24 +0000228 {
Derek Jones47874132009-02-10 17:32:15 +0000229 if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 {
231 show_error('You must submit a valid result object');
Barry Mienydd671972010-10-04 16:33:58 +0200232 }
233
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 $out = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 // First generate the headings from the table column names
236 foreach ($query->list_fields() as $name)
237 {
238 $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
239 }
Barry Mienydd671972010-10-04 16:33:58 +0200240
Michelle Jonesb76e2922013-02-27 16:59:48 -0500241 $out = substr(rtrim($out),0,-strlen($delim)); // Remove the trailing delimiter character(s) at the end of the column names
242 $out = $out.$newline;
Barry Mienydd671972010-10-04 16:33:58 +0200243
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 // Next blast through the result array and build out the rows
Andrey Andreevd06acd82012-05-25 00:29:09 +0300245 while ($row = $query->unbuffered_row('array'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 {
247 foreach ($row as $item)
248 {
Barry Mienydd671972010-10-04 16:33:58 +0200249 $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim;
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 }
Michelle Jonesb76e2922013-02-27 16:59:48 -0500251 $out = substr(rtrim($out),0,-strlen($delim)); // Remove the trailing delimiter character(s) at the end of the row lines
Andrey Andreev24276a32012-01-08 02:44:38 +0200252 $out = rtrim($out).$newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 }
254
255 return $out;
256 }
Barry Mienydd671972010-10-04 16:33:58 +0200257
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 // --------------------------------------------------------------------
259
260 /**
261 * Generate XML data from a query result object
262 *
Andrey Andreevae85eb42012-11-02 01:42:31 +0200263 * @param object $query Query result object
264 * @param array $params Any preferences
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 * @return string
266 */
Andrey Andreev24276a32012-01-08 02:44:38 +0200267 public function xml_from_result($query, $params = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 {
Pascal Kriete69b1fcc2009-08-24 16:42:52 +0000269 if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 {
271 show_error('You must submit a valid result object');
272 }
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 // Set our default values
275 foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val)
276 {
277 if ( ! isset($params[$key]))
278 {
279 $params[$key] = $val;
280 }
281 }
Barry Mienydd671972010-10-04 16:33:58 +0200282
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 // Create variables for convenience
284 extract($params);
Barry Mienydd671972010-10-04 16:33:58 +0200285
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 // Load the xml helper
287 $CI =& get_instance();
288 $CI->load->helper('xml');
289
290 // Generate the result
Andrey Andreevb457a402012-04-09 16:11:56 +0300291 $xml = '<'.$root.'>'.$newline;
Andrey Andreevd06acd82012-05-25 00:29:09 +0300292 while ($row = $query->unbuffered_row())
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300294 $xml .= $tab.'<'.$element.'>'.$newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 foreach ($row as $key => $val)
296 {
Andrey Andreevb457a402012-04-09 16:11:56 +0300297 $xml .= $tab.$tab.'<'.$key.'>'.xml_convert($val).'</'.$key.'>'.$newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 }
Andrey Andreevb457a402012-04-09 16:11:56 +0300299 $xml .= $tab.'</'.$element.'>'.$newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 }
Barry Mienydd671972010-10-04 16:33:58 +0200301
Andrey Andreevb457a402012-04-09 16:11:56 +0300302 return $xml.'</'.$root.'>'.$newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 }
304
305 // --------------------------------------------------------------------
306
307 /**
308 * Database Backup
309 *
Andrey Andreevae85eb42012-11-02 01:42:31 +0200310 * @param array $params
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 * @return void
312 */
Andrey Andreev24276a32012-01-08 02:44:38 +0200313 public function backup($params = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 {
315 // If the parameters have not been submitted as an
316 // array then we know that it is simply the table
317 // name, which is a valid short cut.
318 if (is_string($params))
319 {
320 $params = array('tables' => $params);
321 }
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 // Set up our default preferences
324 $prefs = array(
Andrey Andreev61c4d0a2012-12-20 16:29:29 +0200325 'tables' => array(),
326 'ignore' => array(),
327 'filename' => '',
328 'format' => 'gzip', // gzip, zip, txt
329 'add_drop' => TRUE,
330 'add_insert' => TRUE,
331 'newline' => "\n",
332 'foreign_key_checks' => TRUE
333 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000334
335 // Did the user submit any preferences? If so set them....
336 if (count($params) > 0)
337 {
338 foreach ($prefs as $key => $val)
339 {
340 if (isset($params[$key]))
341 {
342 $prefs[$key] = $params[$key];
343 }
344 }
345 }
346
Barry Mienydd671972010-10-04 16:33:58 +0200347 // Are we backing up a complete database or individual tables?
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 // If no table names were submitted we'll fetch the entire table list
Andrey Andreev24276a32012-01-08 02:44:38 +0200349 if (count($prefs['tables']) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 {
351 $prefs['tables'] = $this->db->list_tables();
352 }
Barry Mienydd671972010-10-04 16:33:58 +0200353
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 // Validate the format
355 if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
356 {
357 $prefs['format'] = 'txt';
358 }
359
Andrey Andreev24276a32012-01-08 02:44:38 +0200360 // Is the encoder supported? If not, we'll either issue an
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 // error or use plain text depending on the debug settings
Andrey Andreevb457a402012-04-09 16:11:56 +0300362 if (($prefs['format'] === 'gzip' && ! @function_exists('gzencode'))
363 OR ($prefs['format'] === 'zip' && ! @function_exists('gzcompress')))
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 {
365 if ($this->db->db_debug)
366 {
Andrey Andreev8d3afde2012-11-06 12:53:47 +0200367 return $this->db->display_error('db_unsupported_compression');
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 }
Barry Mienydd671972010-10-04 16:33:58 +0200369
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 $prefs['format'] = 'txt';
371 }
372
Barry Mienydd671972010-10-04 16:33:58 +0200373 // Was a Zip file requested?
Andrey Andreev24276a32012-01-08 02:44:38 +0200374 if ($prefs['format'] === 'zip')
Derek Allard2067d1a2008-11-13 22:59:24 +0000375 {
Andrey Andreev24276a32012-01-08 02:44:38 +0200376 // Set the filename if not provided (only needed with Zip files)
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100377 if ($prefs['filename'] === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 {
Andrey Andreev24276a32012-01-08 02:44:38 +0200379 $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
380 .date('Y-m-d_H-i', time()).'.sql';
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 }
Andrey Andreev24276a32012-01-08 02:44:38 +0200382 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 {
Andrey Andreev24276a32012-01-08 02:44:38 +0200384 // If they included the .zip file extension we'll remove it
385 if (preg_match('|.+?\.zip$|', $prefs['filename']))
386 {
387 $prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
388 }
389
390 // Tack on the ".sql" file extension if needed
391 if ( ! preg_match('|.+?\.sql$|', $prefs['filename']))
392 {
393 $prefs['filename'] .= '.sql';
394 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 }
396
397 // Load the Zip class and output it
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 $CI =& get_instance();
399 $CI->load->library('zip');
Barry Mienydd671972010-10-04 16:33:58 +0200400 $CI->zip->add_data($prefs['filename'], $this->_backup($prefs));
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 return $CI->zip->get_zip();
402 }
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100403 elseif ($prefs['format'] === 'txt') // Was a text file requested?
Andrey Andreev24276a32012-01-08 02:44:38 +0200404 {
405 return $this->_backup($prefs);
406 }
407 elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested?
408 {
409 return gzencode($this->_backup($prefs));
410 }
Barry Mienydd671972010-10-04 16:33:58 +0200411
Andrey Andreev24276a32012-01-08 02:44:38 +0200412 return;
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 }
414
415}
416
Derek Allard2067d1a2008-11-13 22:59:24 +0000417/* End of file DB_utility.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400418/* Location: ./system/database/DB_utility.php */