function get_table_content_mysql($table, $handler) { global $db; // Grab the data from the table. if (!($result = $db->query("SELECT * FROM {$table}"))) { message_backstage('Failed to get table content'); } // Loop through the resulting rows and build the sql statement. if ($row = $db->fetch_assoc($result)) { $handler("\n#\n# Table Data for {$table}\n#\n"); $field_names = array(); // Grab the list of field names. $num_fields = num_fields($result); $table_list = '('; for ($j = 0; $j < $num_fields; $j++) { $field_names[$j] = field_name($j, $result); $table_list .= ($j > 0 ? ', ' : '') . $field_names[$j]; } $table_list .= ')'; do { // Start building the SQL statement. $schema_insert = "INSERT INTO {$table} {$table_list} VALUES("; // Loop through the rows and fill in data for each column for ($j = 0; $j < $num_fields; $j++) { $schema_insert .= $j > 0 ? ', ' : ''; if (!isset($row[$field_names[$j]])) { // // If there is no data for the column set it to null. // There was a problem here with an extra space causing the // sql file not to reimport if the last column was null in // any table. Should be fixed now :) JLH // $schema_insert .= 'NULL'; } elseif ($row[$field_names[$j]] != '') { $schema_insert .= '\'' . addslashes($row[$field_names[$j]]) . '\''; } else { $schema_insert .= '\'\''; } } $schema_insert .= ');'; // Go ahead and send the insert statement to the handler function. $handler(trim($schema_insert)); } while ($row = $db->fetch_assoc($result)); } return true; }
/** * Get number of fields in a result * @param Mixed qHanle The query handle * @return Number */ public function num_fields($qHandle) { return num_fields($qHandle); }