/ Published in: PHP
Expand |
Embed | Plain Text
{ { return FALSE; } // Extract the prefs for simplicity // Build the output $output = ''; { // Is the table in the "ignore" list? { continue; } // Get the table schema $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.'.$table); // No result means the table name was invalid if ($query === FALSE) { continue; } // Write out the table schema $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; if ($add_drop == TRUE) { $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; } $i = 0; $result = $query->result_array(); foreach ($result[0] as $val) { if ($i++ % 2) { $output .= $val.';'.$newline.$newline; } } // If inserts are not needed we're done... if ($add_insert == FALSE) { continue; } // Grab all the data from the current table $query = $this->db->query("SELECT * FROM $table"); if ($query->num_rows() == 0) { continue; } // Fetch the field names and determine if the field is an // integer type. We use this info to decide whether to // surround the data with quotes or not $i = 0; $field_str = ''; { // Most versions of MySQL store timestamp as a string TRUE) ) ? TRUE : FALSE; // Create a string of field names $field_str .= $field->name.', '; $i++; } // Trim off the end comma // Build the insert string foreach ($query->result_array() as $row) { $val_str = ''; $i = 0; foreach ($row as $v) { // Is the value NULL? if ($v === NULL) { $val_str .= 'NULL'; } else { // Do a little formatting... // Escape the data if it's not an integer if ($is_int[$i] == FALSE) { $val_str .= $this->db->escape($v); } else { $val_str .= $v; } } // Append a comma $val_str .= ', '; $i++; } // Remove the comma at the end of the string // Build the INSERT string $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } $output .= $newline.$newline; } return $output; }
You need to login to post a comment.
