473,242 Members | 1,423 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,242 software developers and data experts.

Charset trouble

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 
  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/
  8. Bug fix by My Digital Life on 22 June 2007.
  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.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. GNU General Public License for more details.
  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
  24. */
  26. echo '<h1>Convert Database to UTF8</h1>';
  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>';
  32. require_once("wp-config.php");
  33. global $wpdb;
  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;
  70.                         default:
  71.                             break;
  72.                     }
  73.                 }
  74. //            }
  75.         }
  76.     }
  77. }
  79. $tables_to_latin1    = '';
  80. $tables_to_utf8        = '';
  81. $columns_to_latin1    = '';
  82. $columns_to_blob    = '';
  83. $columns_to_utf8    = '';
  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. }
  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;
  100. echo nl2br( $complete_sql );
  102. ?>
Oct 13 '09 #1
5 2413
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. ...
Oct 13 '09 #2
249 100+
Sorry, but...
I already did it =/
Oct 13 '09 #3
6,050 Expert 4TB
Try 'utf-8'.
Oct 13 '09 #4
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
249 100+



Oct 14 '09 #6

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

Similar topics

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...
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...
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...
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...
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...
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...
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";...
by: Torsten Bronger | last post by:
Hallöchen! 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...
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)...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.