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