'binary', 'varchar' => 'varbinary', 'tinytext' => 'tinyblob', 'text' => 'blob', 'mediumtext' => 'mediumblob', 'longtext' => 'longblob'); // Get next table in list $convert_to_binary = array(); $convert_to_utf8 = array(); // Set table default charset $ret[] = update_sql('ALTER TABLE {'. $table .'} DEFAULT CHARACTER SET utf8'); // Find out which columns need converting and build SQL statements $result = db_query('SHOW FULL COLUMNS FROM {'. $table .'}'); while ($column = db_fetch_array($result)) { list($type) = explode('(', $column['Type']); if (isset($types[$type])) { $names = 'CHANGE `'. $column['Field'] .'` `'. $column['Field'] .'` '; $attributes = ' DEFAULT '. ($column['Default'] == 'NULL' ? 'NULL ' : "'". db_escape_string($column['Default']) ."' ") . ($column['Null'] == 'YES' ? 'NULL' : 'NOT NULL'); $convert_to_binary[] = $names . preg_replace('/'. $type .'/i', $types[$type], $column['Type']) . $attributes; $convert_to_utf8[] = $names . $column['Type'] .' CHARACTER SET utf8'. $attributes; } } if (count($convert_to_binary)) { // Convert text columns to binary $ret[] = update_sql('ALTER TABLE {'. $table .'} '. implode(', ', $convert_to_binary)); // Convert binary columns to UTF-8 $ret[] = update_sql('ALTER TABLE {'. $table .'} '. implode(', ', $convert_to_utf8)); } return $ret; } function update_sql($sql) { $result = db_query($sql); return array('success' => $result !== FALSE, 'query' => check_plain($sql)); } ?>