1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
22 * @author ExpressionEngine Dev Team
23 * @link http://codeigniter.com/user_guide/database/
25 class CI_DB_mysql_utility extends CI_DB_utility {
33 function _list_databases()
35 return "SHOW DATABASES";
38 // --------------------------------------------------------------------
41 * Optimize table query
43 * Generates a platform-specific query so that a table can be optimized
46 * @param string the table name
49 function _optimize_table($table)
51 return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table);
54 // --------------------------------------------------------------------
59 * Generates a platform-specific query so that a table can be repaired
62 * @param string the table name
65 function _repair_table($table)
67 return "REPAIR TABLE ".$this->db->_escape_identifiers($table);
70 // --------------------------------------------------------------------
75 * @param array Preferences
78 function _backup($params = array())
80 if (count($params) == 0)
85 // Extract the prefs for simplicity
90 foreach ((array)$tables as $table)
92 // Is the table in the "ignore" list?
93 if (in_array($table, (array)$ignore, TRUE))
98 // Get the table schema
99 $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.'.$table);
101 // No result means the table name was invalid
102 if ($query === FALSE)
107 // Write out the table schema
108 $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
110 if ($add_drop == TRUE)
112 $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline;
116 $result = $query->result_array();
117 foreach ($result[0] as $val)
121 $output .= $val.';'.$newline.$newline;
125 // If inserts are not needed we're done...
126 if ($add_insert == FALSE)
131 // Grab all the data from the current table
132 $query = $this->db->query("SELECT * FROM $table");
134 if ($query->num_rows() == 0)
139 // Fetch the field names and determine if the field is an
140 // integer type. We use this info to decide whether to
141 // surround the data with quotes or not
146 while ($field = mysql_fetch_field($query->result_id))
148 // Most versions of MySQL store timestamp as a string
149 $is_int[$i] = (in_array(
150 strtolower(mysql_field_type($query->result_id, $i)),
151 array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
155 // Create a string of field names
156 $field_str .= '`'.$field->name.'`, ';
160 // Trim off the end comma
161 $field_str = preg_replace( "/, $/" , "" , $field_str);
164 // Build the insert string
165 foreach ($query->result_array() as $row)
172 // Is the value NULL?
179 // Escape the data if it's not an integer
180 if ($is_int[$i] == FALSE)
182 $val_str .= $this->db->escape($v);
195 // Remove the comma at the end of the string
196 $val_str = preg_replace( "/, $/" , "" , $val_str);
198 // Build the INSERT string
199 $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
202 $output .= $newline.$newline;
209 /* End of file mysql_utility.php */
210 /* Location: ./system/database/drivers/mysql/mysql_utility.php */