Only the blog owner has the access capabilities to this resource.'); if ( $_POST['next'] == 1 ) $dialog = 1; if ( $_POST['mode'] == 'expert' ) $dialog = 2; if ( $_POST['mode'] == 'normal' ) { $dialog = 3; $selected_tables = implode(',', (array) $_SESSION['utf8_db_converter_tables']); $collation = $_SESSION['utf8_db_converter_collations'][0]; $output = 'direct'; } if ( $_POST['next'] == 3 ) { $dialog = 3; $selected_tables = implode(',', $_POST['tables']); $collation = $_POST['collation']; $output = $_POST['output']; UTF8_DB_Converter_validate($_POST['tables'], $collation, $output); } if ( $_POST['next'] == 4 ) { $dialog = 4; $tables = explode(',', $_POST['tables']); $collation = $_POST['collation']; $output = $_POST['output']; UTF8_DB_Converter_validate($tables, $collation, $output); $total_tables = count((array) $_SESSION['utf8_db_converter_tables']); $selected_total_tables = count($tables); } } ?>

UTF-8 Database Converter

WARNING
VERSION NOT SUPPORTED

We have detected an a unsupported version of WordPress, although we have made our best efforts to find the very best solution, we cannot be sure that it will still working as expected under any minor or major version of WordPress.

If you still want to use it after this warning proceed with the next step.

« Welcome to the UTF-8 Database Converter »

Before proceeding with the next step, we first need you to select what mode should the converter start, next to this paragraph is a little explanation about every mode that the converter currently have:

Normal Mode
This mode will use the default options so it will not ask you about anything.
This mode is perfect for people that not have any knowledge about the problem or just want a 1-step converter.
Default options includes: all tables in the database, use of general collation and it will convert the database right now.

Expert Mode
This mode will ask you to select what tables, collation and output should the converter use during converting process.
This mode is perfect for people that have partial or full knowledge about the problem and they need some special option, eg: for web sites that share the same database for different web projects.

Select Mode

« Expert Mode »

1. Select Tables

2. Select Collation

3. Select Output

Do It Right Now
Just Generate the SQL Sentences

WARNING
DATA MAY BE LOST

Before proceeding with the next and final step we advice you to make a COMPLETE BACKUP of your WordPress Based Website and also is very recommendable that you double check its integrity in order to avoid any further problem.

The next procedure may take some several time based on how big is your database, so don't close your web browser or your internet connection during the procedure also its very recommendable that you close the access of your WordPress based site.

Seleccionado:

\n"; print '
' . $_POST['collation'] . "
\n"; print '
' . $_POST['output'] . "
\n"; ?>

Error establishing a database connection'); @mysql_select_db(DB_NAME, $link_id) or wp_die('

Can’t select database

'); $resource = mysql_query('SHOW TABLES', $link_id); while ( $result = mysql_fetch_row($resource) ) $tables[] = $result[0]; $resource = mysql_query("SHOW COLLATION LIKE 'utf8%'", $link_id); while ( $result = mysql_fetch_assoc($resource) ) { if ( 'Yes' == $result['Compiled'] ) $collations[] = $result['Collation']; } $_SESSION['utf8_db_converter_tables'] = $tables; $_SESSION['utf8_db_converter_collations'] = $collations; @mysql_close($link_id); } } // WhiteList-Based Very Simple Protection against common injections function UTF8_DB_Converter_validate($tables, $collation, $output) { $valid = true; foreach ( (array) $tables as $table ) { if ( array_search($table, (array) $_SESSION['utf8_db_converter_tables']) === false ) $valid = false; } if ( array_search($collation, (array) $_SESSION['utf8_db_converter_collations']) === false ) $valid = false; if ( array_search($output, array('direct', 'sql')) === false ) $valid = false; if ( !$valid ) wp_die('

Detected possible injection

'); } function UTF8_DB_Converter_core($tables, $collation, $complete_convert = true) { // Initialize vars. $string_querys = array(); $binary_querys = array(); $gen_index_querys = array(); $drop_index_querys = array(); $final_querys = array(); // Since we cannot use the WordPress DB Class Object (wp-includes/wp-db.php), // we have to make a stand-alone connection to the database. $link_id = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or wp_die('

Error establishing a database connection

'); @mysql_select_db(DB_NAME, $link_id) or wp_die('

Can’t select database

'); // Begin Converter Core if ( !empty($tables) ) { foreach ( (array) $tables as $table ) { // Analyze tables for string types columns and generate his binary and string correctness sql sentences. $resource = mysql_query("DESCRIBE $table", $link_id); while ( $result = mysql_fetch_assoc($resource) ) { if ( preg_match('/(char)|(text)|(enum)|(set)/', $result['Type']) ) { // String Type SQL Sentence. $string_querys[] = "ALTER TABLE $table MODIFY " . $result['Field'] . ' ' . $result['Type'] . " CHARACTER SET utf8 COLLATE $collation " . ( ( (!empty($result['Default'])) || ($result['Default'] === '0') || ($result['Default'] === 0) ) ? "DEFAULT '". $result['Default'] ."' " : '' ) . ( 'YES' == $result['Null'] ? '' : 'NOT ' ) . 'NULL'; // Binary String Type SQL Sentence. if ( preg_match('/(enum)|(set)/', $result['Type']) ) { $binary_querys[] = "ALTER TABLE $table MODIFY " . $result['Field'] . ' ' . $result['Type'] . ' CHARACTER SET binary ' . ( ( (!empty($result['Default'])) || ($result['Default'] === '0') || ($result['Default'] === 0) ) ? "DEFAULT '". $result['Default'] ."' " : '' ) . ( 'YES' == $result['Null'] ? '' : 'NOT ' ) . 'NULL'; } else { $result['Type'] = preg_replace('/char/', 'binary', $result['Type']); $result['Type'] = preg_replace('/text/', 'blob', $result['Type']); $binary_querys[] = "ALTER TABLE $table MODIFY " . $result['Field'] . ' ' . $result['Type'] . ' ' . ( ( (!empty($result['Default'])) || ($result['Default'] === '0') || ($result['Default'] === 0) ) ? "DEFAULT '". $result['Default'] ."' " : '' ) . ( 'YES' == $result['Null'] ? '' : 'NOT ' ) . 'NULL'; } } } // Analyze table indexs for any FULLTEXT-Type of index in the table. $fulltext_indexes = array(); $resource = mysql_query("SHOW INDEX FROM $table", $link_id); while ( $result = mysql_fetch_assoc($resource) ) { if ( preg_match('/FULLTEXT/', $result['Index_type']) ) $fulltext_indexes[$result['Key_name']][$result['Column_name']] = 1; } // Generate the SQL Sentence for drop and add every FULLTEXT index we found previously. if ( !empty($fulltext_indexes) ) { foreach ( (array) $fulltext_indexes as $key_name => $column ) { $drop_index_querys[] = "ALTER TABLE $table DROP INDEX $key_name"; $tmp_gen_index_query = "ALTER TABLE $table ADD FULLTEXT $key_name("; $fields_names = array_keys($column); for ($i = 1; $i <= count($column); $i++) $tmp_gen_index_query .= $fields_names[$i - 1] . (($i == count($column)) ? '' : ', '); $gen_index_querys[] = $tmp_gen_index_query . ')'; } } // Generate the SQL Sentence for change default table character set. $tables_querys[] = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE $collation"; // Generate the SQL Sentence for Optimize Table. $optimize_querys[] = "OPTIMIZE TABLE $table"; } // SQL Sentence for change the default database character set. if ( $complete_convert ) $db_query = "ALTER DATABASE " . DB_NAME . " DEFAULT CHARACTER SET utf8 COLLATE $collation"; } else { wp_die('

There are no tables?

'); } // End Converter Core // Close MySQL Link. @mysql_close($link_id); // Merge all SQL Sentences that we temporary store in arrays. $final_querys = array_merge( (array) $drop_index_querys, (array) $binary_querys, (array) $db_query, (array) $tables_querys, (array) $string_querys, (array) $gen_index_querys, (array) $optimize_querys ); // Time to return. return $final_querys; } function UTF8_DB_Converter_do_querys($querys) { /* if ( (!empty(mysql_error($link_id))) && (!empty(mysql_errno($link_id))) ) return "Error " . mysql_errno($link_id) . ": " . mysql_error($link_id); else return false; */ } add_action('admin_menu', 'UTF8_DB_Converter_menu_add'); ?>