473,413 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Charset trouble

matheussousuke
249 100+
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
5 2421
Markus
6,050 Expert 4TB
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
249 100+
Sorry, but...
I already did it =/
Oct 13 '09 #3
Markus
6,050 Expert 4TB
Try 'utf-8'.
Oct 13 '09 #4
matheussousuke
249 100+
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
249 100+
Anyone?

...

...

...
Oct 14 '09 #6

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

Similar topics

3
by: LMachado1 | last post by:
I just started with php and I'm trying to make a simple interface as follows: - user is asked to input an integers, for example: how many students do you want to enter? - user is then shown a...
9
by: Jakle | last post by:
I'm trying to write a program (with my very limited knowledge of python) that will convert text I type into those letters drawn with ascii symbols. I did 2 letters then went to test it. Here's the...
37
by: Haines Brown | last post by:
I understand that <br /> is marginal in CSS, and so am looking for a substitute for the EOL character. I've failed in both approaches and seek advice. The first thing I tried was to use the...
1
by: stevelooking41 | last post by:
Can someone explain why I don't seem unable to use document.write to produce a valid UTF-8 none breaking space sequence (Hex: C2A0) ? I've tried everyway I've been able to find to tell the...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
3
by: Michael | last post by:
Hi all, I'm having trouble PInvoking a TCHAR within a struct. I'll paste the specific struct's API definition below. I've tried so many numerous variations. The main Win32 error I get is...
1
by: Marc Scheuner | last post by:
Folks, we're trying to stream back a result set from a SQL query into Excel from our ASP.NET application. Basically, we're doing this here: Response.ContentType = "text/csv";...
2
by: Torsten Bronger | last post by:
Hallchen! I thought that with the following code snippet, I could generate a MIME email stub: #!/usr/bin/env python # -*- coding: utf-8 -*- from email.MIMEText import MIMEText from...
8
by: cutlass | last post by:
Need you assistance to anyone who is willing to offer. I have been working on this script and can't get it to work. The issue I'm having is the statement: function validateSender($Address)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.