By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Charset trouble

matheussousuke
100+
P: 249
Hi guys, good morning.

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
  1. <?php
  2. /*
  3. Template Name: Convert Database to UTF8 
  4.  
  5. Copyright 2007  Anders Stalheim Oefsdahl  (email : anders@apt.no)
  6. Detail at http://www.mydigitallife.info/2007/07/22/how-to-convert-character-set-and-collation-of-wordpress-database/
  7.  
  8. Bug fix by My Digital Life on 22 June 2007.
  9.  
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14.  
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  
  24. */
  25.  
  26. echo '<h1>Convert Database to UTF8</h1>';
  27.  
  28. 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>';
  29. 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>';
  30. 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>';
  31.  
  32. require_once("wp-config.php");
  33. global $wpdb;
  34.  
  35. /**
  36.  * Fetch all tables
  37.  */
  38. $tables = array();
  39. $sql_tables = "SHOW TABLES";
  40. $res_tables = $wpdb->get_results( $sql_tables );
  41. if( is_array( $res_tables ) ){
  42.     foreach( $res_tables as $res_table ){
  43.         if(strpos($res_table->Tables_in_DATABASENAME, $table_prefix) === 0)
  44.         $tables[$res_table->Tables_in_DATABASENAME] = array();
  45.     }
  46. }
  47. /**
  48.  * Loop all tables fetching each table's fields and filter out fields of type CHAR, VARCHAR, TEXT, ENUM, and SET (and related variations)
  49.  */
  50. if( count( $tables )>0 ){
  51.     foreach( $tables as $table=>$fields ){
  52. //        if (strpos($table_prefix, $table) == 0)
  53. //        {
  54.             $sql_fields = "EXPLAIN ".$table;
  55.             $res_fields = $wpdb->get_results( $sql_fields );
  56.             if( is_array( $res_fields ) ){
  57.                 foreach( $res_fields as $field ){
  58.                     switch( TRUE ){
  59.                         case strpos( strtolower( $field->Type ), 'char' )===0:
  60.                         case strpos( strtolower( $field->Type ), 'varchar' )===0:
  61.                         case strpos( strtolower( $field->Type ), 'text' )===0:
  62.                         case strpos( strtolower( $field->Type ), 'enum' )===0:
  63.                         case strpos( strtolower( $field->Type ), 'set' )===0:
  64.                         case strpos( strtolower( $field->Type ), 'tinytext' )===0:
  65.                         case strpos( strtolower( $field->Type ), 'mediumtext' )===0:
  66.                         case strpos( strtolower( $field->Type ), 'longtext' )===0:
  67.                             $tables[$table][$field->Field] = $field->Type;
  68.                             break;
  69.  
  70.                         default:
  71.                             break;
  72.                     }
  73.                 }
  74. //            }
  75.         }
  76.     }
  77. }
  78.  
  79. $tables_to_latin1    = '';
  80. $tables_to_utf8        = '';
  81. $columns_to_latin1    = '';
  82. $columns_to_blob    = '';
  83. $columns_to_utf8    = '';
  84.  
  85. foreach( $tables as $table=>$fields ){
  86.     $tables_to_latin1 .= "\nALTER TABLE ".$table." DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;";
  87.     $tables_to_utf8 .= "\nALTER TABLE ".$table." DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
  88.     if( count( $fields )>0 ){
  89.         foreach( $fields as $name=>$type ){
  90.             $columns_to_latin1 .= "\nALTER TABLE ".$table." MODIFY ".$name." CHARACTER SET latin1 COLLATE latin1_swedish_ci;";
  91.             $columns_to_blob .= "\nALTER TABLE ".$table." MODIFY ".$name." BLOB;";
  92.             $columns_to_utf8 .= "\nALTER TABLE ".$table." MODIFY ".$name." ".$type.";";
  93.         }
  94.     }
  95. }
  96.  
  97. //$complete_sql = $sql_to_blob."\nALTER DATABASE ".DB_NAME." charset=utf8;".$sql_to_utf8.$sql_to_original;
  98. $complete_sql = $tables_to_latin1."\n".$columns_to_latin1."\n".$columns_to_blob."\n".$tables_to_utf8."\n".$columns_to_utf8;
  99.  
  100. echo nl2br( $complete_sql );
  101.  
  102. ?>
Oct 13 '09 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
This seems like overkill. You might just change the content-type header of the page to something like: ISO-8859-1.

Expand|Select|Wrap|Line Numbers
  1. <head>
  2.  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  3. </head>
  4. <body>
  5. ...
  6.  
Oct 13 '09 #2

matheussousuke
100+
P: 249
Sorry, but...
I already did it =/
Oct 13 '09 #3

Markus
Expert 5K+
P: 6,050
Try 'utf-8'.
Oct 13 '09 #4

matheussousuke
100+
P: 249
It doesn't works, I tried both. That friend of mine told me that the trouble is with the server, that I should install a script that correct that. She did it in her server, made a script and it worked,
I asked if she could handle me the script but she sad she spent hours making it, now I found that one on the internet, shown her and she said that it will work if I install it corretly, she tryied to teach me how to install and configurate but dindt has too much time, she has been pretty busy.
Oct 13 '09 #5

matheussousuke
100+
P: 249
Anyone?

...

...

...
Oct 14 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.