Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 3 | * CodeIgniter |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Database Utility Class |
| 32 | * |
| 33 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
| 37 | class CI_DB_utility extends CI_DB_forge { |
| 38 | |
| 39 | var $db; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 40 | var $data_cache = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Constructor |
| 44 | * |
| 45 | * Grabs the CI super object instance so we can access it. |
| 46 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 47 | */ |
Timothy Warren | a2097a0 | 2011-10-10 10:10:46 -0400 | [diff] [blame] | 48 | function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | { |
| 50 | // Assign the main database object to $this->db |
| 51 | $CI =& get_instance(); |
| 52 | $this->db =& $CI->db; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 53 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 54 | log_message('debug', "Database Utility Class Initialized"); |
| 55 | } |
| 56 | |
| 57 | // -------------------------------------------------------------------- |
| 58 | |
| 59 | /** |
| 60 | * List databases |
| 61 | * |
| 62 | * @access public |
| 63 | * @return bool |
| 64 | */ |
| 65 | function list_databases() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 66 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 67 | // Is there a cached result? |
| 68 | if (isset($this->data_cache['db_names'])) |
| 69 | { |
| 70 | return $this->data_cache['db_names']; |
| 71 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 72 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | $query = $this->db->query($this->_list_databases()); |
| 74 | $dbs = array(); |
| 75 | if ($query->num_rows() > 0) |
| 76 | { |
| 77 | foreach ($query->result_array() as $row) |
| 78 | { |
| 79 | $dbs[] = current($row); |
| 80 | } |
| 81 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 82 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | $this->data_cache['db_names'] = $dbs; |
| 84 | return $this->data_cache['db_names']; |
| 85 | } |
| 86 | |
| 87 | // -------------------------------------------------------------------- |
| 88 | |
| 89 | /** |
Derek Allard | e7f0325 | 2010-02-04 16:47:01 +0000 | [diff] [blame] | 90 | * Determine if a particular database exists |
| 91 | * |
| 92 | * @access public |
| 93 | * @param string |
| 94 | * @return boolean |
| 95 | */ |
| 96 | function database_exists($database_name) |
Derek Allard | 6239623 | 2010-02-04 17:45:47 +0000 | [diff] [blame] | 97 | { |
| 98 | // Some databases won't have access to the list_databases() function, so |
| 99 | // this is intended to allow them to override with their own functions as |
| 100 | // defined in $driver_utility.php |
| 101 | if (method_exists($this, '_database_exists')) |
| 102 | { |
| 103 | return $this->_database_exists($database_name); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; |
| 108 | } |
Derek Allard | e7f0325 | 2010-02-04 16:47:01 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Derek Allard | 6239623 | 2010-02-04 17:45:47 +0000 | [diff] [blame] | 111 | |
Derek Allard | e7f0325 | 2010-02-04 16:47:01 +0000 | [diff] [blame] | 112 | // -------------------------------------------------------------------- |
| 113 | |
| 114 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 115 | * Optimize Table |
| 116 | * |
| 117 | * @access public |
| 118 | * @param string the table name |
| 119 | * @return bool |
| 120 | */ |
| 121 | function optimize_table($table_name) |
| 122 | { |
| 123 | $sql = $this->_optimize_table($table_name); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 124 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 125 | if (is_bool($sql)) |
| 126 | { |
| 127 | show_error('db_must_use_set'); |
| 128 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 129 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | $query = $this->db->query($sql); |
| 131 | $res = $query->result_array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 132 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | // Note: Due to a bug in current() that affects some versions |
| 134 | // of PHP we can not pass function call directly into it |
| 135 | return current($res); |
| 136 | } |
| 137 | |
| 138 | // -------------------------------------------------------------------- |
| 139 | |
| 140 | /** |
| 141 | * Optimize Database |
| 142 | * |
| 143 | * @access public |
| 144 | * @return array |
| 145 | */ |
| 146 | function optimize_database() |
| 147 | { |
| 148 | $result = array(); |
| 149 | foreach ($this->db->list_tables() as $table_name) |
| 150 | { |
| 151 | $sql = $this->_optimize_table($table_name); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 152 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 153 | if (is_bool($sql)) |
| 154 | { |
| 155 | return $sql; |
| 156 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 157 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 158 | $query = $this->db->query($sql); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 159 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 160 | // Build the result array... |
| 161 | // Note: Due to a bug in current() that affects some versions |
| 162 | // of PHP we can not pass function call directly into it |
| 163 | $res = $query->result_array(); |
| 164 | $res = current($res); |
| 165 | $key = str_replace($this->db->database.'.', '', current($res)); |
| 166 | $keys = array_keys($res); |
| 167 | unset($res[$keys[0]]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 168 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | $result[$key] = $res; |
| 170 | } |
| 171 | |
| 172 | return $result; |
| 173 | } |
| 174 | |
| 175 | // -------------------------------------------------------------------- |
| 176 | |
| 177 | /** |
| 178 | * Repair Table |
| 179 | * |
| 180 | * @access public |
| 181 | * @param string the table name |
| 182 | * @return bool |
| 183 | */ |
| 184 | function repair_table($table_name) |
| 185 | { |
| 186 | $sql = $this->_repair_table($table_name); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 187 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 188 | if (is_bool($sql)) |
| 189 | { |
| 190 | return $sql; |
| 191 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 192 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | $query = $this->db->query($sql); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 194 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | // Note: Due to a bug in current() that affects some versions |
| 196 | // of PHP we can not pass function call directly into it |
| 197 | $res = $query->result_array(); |
| 198 | return current($res); |
| 199 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 200 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | // -------------------------------------------------------------------- |
| 202 | |
| 203 | /** |
| 204 | * Generate CSV from a query result object |
| 205 | * |
| 206 | * @access public |
| 207 | * @param object The query result object |
| 208 | * @param string The delimiter - comma by default |
| 209 | * @param string The newline character - \n by default |
| 210 | * @param string The enclosure - double quote by default |
| 211 | * @return string |
| 212 | */ |
| 213 | function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') |
| 214 | { |
Derek Jones | 4787413 | 2009-02-10 17:32:15 +0000 | [diff] [blame] | 215 | if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 216 | { |
| 217 | show_error('You must submit a valid result object'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 220 | $out = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 221 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 222 | // First generate the headings from the table column names |
| 223 | foreach ($query->list_fields() as $name) |
| 224 | { |
| 225 | $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; |
| 226 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 227 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | $out = rtrim($out); |
| 229 | $out .= $newline; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 230 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | // Next blast through the result array and build out the rows |
| 232 | foreach ($query->result_array() as $row) |
| 233 | { |
| 234 | foreach ($row as $item) |
| 235 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 236 | $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 237 | } |
| 238 | $out = rtrim($out); |
| 239 | $out .= $newline; |
| 240 | } |
| 241 | |
| 242 | return $out; |
| 243 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 244 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | // -------------------------------------------------------------------- |
| 246 | |
| 247 | /** |
| 248 | * Generate XML data from a query result object |
| 249 | * |
| 250 | * @access public |
| 251 | * @param object The query result object |
| 252 | * @param array Any preferences |
| 253 | * @return string |
| 254 | */ |
| 255 | function xml_from_result($query, $params = array()) |
| 256 | { |
Pascal Kriete | 69b1fcc | 2009-08-24 16:42:52 +0000 | [diff] [blame] | 257 | if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 258 | { |
| 259 | show_error('You must submit a valid result object'); |
| 260 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 261 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | // Set our default values |
| 263 | foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) |
| 264 | { |
| 265 | if ( ! isset($params[$key])) |
| 266 | { |
| 267 | $params[$key] = $val; |
| 268 | } |
| 269 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 270 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 271 | // Create variables for convenience |
| 272 | extract($params); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 273 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 274 | // Load the xml helper |
| 275 | $CI =& get_instance(); |
| 276 | $CI->load->helper('xml'); |
| 277 | |
| 278 | // Generate the result |
| 279 | $xml = "<{$root}>".$newline; |
| 280 | foreach ($query->result_array() as $row) |
| 281 | { |
| 282 | $xml .= $tab."<{$element}>".$newline; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 283 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | foreach ($row as $key => $val) |
| 285 | { |
| 286 | $xml .= $tab.$tab."<{$key}>".xml_convert($val)."</{$key}>".$newline; |
| 287 | } |
| 288 | $xml .= $tab."</{$element}>".$newline; |
| 289 | } |
| 290 | $xml .= "</$root>".$newline; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 291 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | return $xml; |
| 293 | } |
| 294 | |
| 295 | // -------------------------------------------------------------------- |
| 296 | |
| 297 | /** |
| 298 | * Database Backup |
| 299 | * |
| 300 | * @access public |
| 301 | * @return void |
| 302 | */ |
| 303 | function backup($params = array()) |
| 304 | { |
| 305 | // If the parameters have not been submitted as an |
| 306 | // array then we know that it is simply the table |
| 307 | // name, which is a valid short cut. |
| 308 | if (is_string($params)) |
| 309 | { |
| 310 | $params = array('tables' => $params); |
| 311 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 312 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | // ------------------------------------------------------ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 314 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 315 | // Set up our default preferences |
| 316 | $prefs = array( |
| 317 | 'tables' => array(), |
| 318 | 'ignore' => array(), |
| 319 | 'filename' => '', |
| 320 | 'format' => 'gzip', // gzip, zip, txt |
| 321 | 'add_drop' => TRUE, |
| 322 | 'add_insert' => TRUE, |
| 323 | 'newline' => "\n" |
| 324 | ); |
| 325 | |
| 326 | // Did the user submit any preferences? If so set them.... |
| 327 | if (count($params) > 0) |
| 328 | { |
| 329 | foreach ($prefs as $key => $val) |
| 330 | { |
| 331 | if (isset($params[$key])) |
| 332 | { |
| 333 | $prefs[$key] = $params[$key]; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | // ------------------------------------------------------ |
| 339 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 340 | // Are we backing up a complete database or individual tables? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | // If no table names were submitted we'll fetch the entire table list |
| 342 | if (count($prefs['tables']) == 0) |
| 343 | { |
| 344 | $prefs['tables'] = $this->db->list_tables(); |
| 345 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 346 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | // ------------------------------------------------------ |
| 348 | |
| 349 | // Validate the format |
| 350 | if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) |
| 351 | { |
| 352 | $prefs['format'] = 'txt'; |
| 353 | } |
| 354 | |
| 355 | // ------------------------------------------------------ |
| 356 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 357 | // Is the encoder supported? If not, we'll either issue an |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 358 | // error or use plain text depending on the debug settings |
| 359 | if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 360 | OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 361 | { |
| 362 | if ($this->db->db_debug) |
| 363 | { |
| 364 | return $this->db->display_error('db_unsuported_compression'); |
| 365 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 366 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | $prefs['format'] = 'txt'; |
| 368 | } |
| 369 | |
| 370 | // ------------------------------------------------------ |
| 371 | |
| 372 | // Set the filename if not provided - Only needed with Zip files |
| 373 | if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') |
| 374 | { |
| 375 | $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; |
| 376 | $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); |
| 377 | } |
| 378 | |
| 379 | // ------------------------------------------------------ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 380 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 381 | // Was a Gzip file requested? |
| 382 | if ($prefs['format'] == 'gzip') |
| 383 | { |
| 384 | return gzencode($this->_backup($prefs)); |
| 385 | } |
| 386 | |
| 387 | // ------------------------------------------------------ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 388 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 389 | // Was a text file requested? |
| 390 | if ($prefs['format'] == 'txt') |
| 391 | { |
| 392 | return $this->_backup($prefs); |
| 393 | } |
| 394 | |
| 395 | // ------------------------------------------------------ |
| 396 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 397 | // Was a Zip file requested? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | if ($prefs['format'] == 'zip') |
| 399 | { |
| 400 | // If they included the .zip file extension we'll remove it |
| 401 | if (preg_match("|.+?\.zip$|", $prefs['filename'])) |
| 402 | { |
| 403 | $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); |
| 404 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | // Tack on the ".sql" file extension if needed |
| 407 | if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) |
| 408 | { |
| 409 | $prefs['filename'] .= '.sql'; |
| 410 | } |
| 411 | |
| 412 | // Load the Zip class and output it |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 413 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | $CI =& get_instance(); |
| 415 | $CI->load->library('zip'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 416 | $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 417 | return $CI->zip->get_zip(); |
| 418 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 419 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | } |
| 423 | |
| 424 | |
| 425 | /* End of file DB_utility.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 426 | /* Location: ./system/database/DB_utility.php */ |