I've just get this script for converting mysql tables from wordpress, and I want to use it in my server, but no with wordpress, with oscommerce, a friend of mine told me a few things I should do for make it working, but less than a rookie in PHP, began studying it now ", and sure I dont know how to use command line yet, she told me something about using command line along with FTP ascii table, I'm lost, couldn't do that, how do I install it? How do I configurate it?
Ps: the script is for converting ascii characters for utf-8 or latin1. If u have anything else that can help me instead of using it, please let me know, here u see how's oscommerce http://www.mghospedagem.com/catalog/
u can see on the left that there are strange characters (oscommerce chars configuration is correct, the trouble's with the server, I contacted em but they didn't nothing, that's why I'm trying to install this script)
Here goes the script "convert_to_utf8_sql_generator_extended.txt"
Expand|Select|Wrap|Line Numbers
- <?php
- /*
- Template Name: Convert Database to UTF8
- Copyright 2007 Anders Stalheim Oefsdahl (email : anders@apt.no)
- Detail at http://www.mydigitallife.info/2007/07/22/how-to-convert-character-set-and-collation-of-wordpress-database/
- Bug fix by My Digital Life on 22 June 2007.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- echo '<h1>Convert Database to UTF8</h1>';
- echo '<p>This script generates SQL to convert existing tables to utf8, following the guide at <a href="http://codex.wordpress.org/Converting_Database_Character_Sets">http://codex.wordpress.org/Converting_Database_Character_Sets</a>, temporarily setting various fields to BLOB before setting them back to their respective types.</p>';
- echo '<p>This is an extended script for databases which are already utf8 but the strings are in latin1. It converts existing tables and colums to latin1 before the BLOB conversion</p>';
- echo '<p>Please note that you probably will get some errors running the scripts, regarding key length on some tables. These errors can be ignored (at least I did :).</p>';
- require_once("wp-config.php");
- global $wpdb;
- /**
- * Fetch all tables
- */
- $tables = array();
- $sql_tables = "SHOW TABLES";
- $res_tables = $wpdb->get_results( $sql_tables );
- if( is_array( $res_tables ) ){
- foreach( $res_tables as $res_table ){
- if(strpos($res_table->Tables_in_DATABASENAME, $table_prefix) === 0)
- $tables[$res_table->Tables_in_DATABASENAME] = array();
- }
- }
- /**
- * Loop all tables fetching each table's fields and filter out fields of type CHAR, VARCHAR, TEXT, ENUM, and SET (and related variations)
- */
- if( count( $tables )>0 ){
- foreach( $tables as $table=>$fields ){
- // if (strpos($table_prefix, $table) == 0)
- // {
- $sql_fields = "EXPLAIN ".$table;
- $res_fields = $wpdb->get_results( $sql_fields );
- if( is_array( $res_fields ) ){
- foreach( $res_fields as $field ){
- switch( TRUE ){
- case strpos( strtolower( $field->Type ), 'char' )===0:
- case strpos( strtolower( $field->Type ), 'varchar' )===0:
- case strpos( strtolower( $field->Type ), 'text' )===0:
- case strpos( strtolower( $field->Type ), 'enum' )===0:
- case strpos( strtolower( $field->Type ), 'set' )===0:
- case strpos( strtolower( $field->Type ), 'tinytext' )===0:
- case strpos( strtolower( $field->Type ), 'mediumtext' )===0:
- case strpos( strtolower( $field->Type ), 'longtext' )===0:
- $tables[$table][$field->Field] = $field->Type;
- break;
- default:
- break;
- }
- }
- // }
- }
- }
- }
- $tables_to_latin1 = '';
- $tables_to_utf8 = '';
- $columns_to_latin1 = '';
- $columns_to_blob = '';
- $columns_to_utf8 = '';
- foreach( $tables as $table=>$fields ){
- $tables_to_latin1 .= "\nALTER TABLE ".$table." DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;";
- $tables_to_utf8 .= "\nALTER TABLE ".$table." DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
- if( count( $fields )>0 ){
- foreach( $fields as $name=>$type ){
- $columns_to_latin1 .= "\nALTER TABLE ".$table." MODIFY ".$name." CHARACTER SET latin1 COLLATE latin1_swedish_ci;";
- $columns_to_blob .= "\nALTER TABLE ".$table." MODIFY ".$name." BLOB;";
- $columns_to_utf8 .= "\nALTER TABLE ".$table." MODIFY ".$name." ".$type.";";
- }
- }
- }
- //$complete_sql = $sql_to_blob."\nALTER DATABASE ".DB_NAME." charset=utf8;".$sql_to_utf8.$sql_to_original;
- $complete_sql = $tables_to_latin1."\n".$columns_to_latin1."\n".$columns_to_blob."\n".$tables_to_utf8."\n".$columns_to_utf8;
- echo nl2br( $complete_sql );
- ?>