I have a problem with MySQL and charsets .
When I insert something into my mysql database, the special chars like "é" change into "è" and some other strange character combinations...
Searching on the web, I read about set utf8_unicode_ci tables and general configuration. I also added the following line to my webpage
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
But after all this it always returns the same error when I insert something into the database. The characters are still garbled.
What do I miss?
You might want to add this to your code:
mysql_query("SET CHARACTER SET utf8");
It will tell PHP to use Unicode to talk with the database engine. So if your form data encoding is unicode too, you shouldn't have any garbled characters problems anymore.
Related
I'm trying to load data from a MySQL DB from a varchar(35) / utf8_swedish_ci field through TBS (tinybutstrong) and PHP using the example (MySQL data merge). My issue is that data loads fine if only ascii characters are in the fields but as soon as I add a single scandinavian special character like ö or ä the field contents vanishes entirely and other fields in row display correctly.
My understanding is that the latest versions on TBS automatically use UTF-8 coding (I have 3.9.0 for PHP 5) so I assumed it would work out-of-the-box. To be safe, I even added the coding to template as so:
'$TBS->LoadTemplate('mysql.html','UTF-8');' but to no avail.
Could someone please advice what is causing this.
For a good UTF-8 processing, all elements of the chain must be UTF-8.
You have to ensure that your template is UTF-8 : check the entered text and the HTML element <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
You have to ensure that all your PHP scripts are UTF-8 and not Ansi.
You also have to ensure that your MySQL connection is set to receive UTF-8 queries and to return UTF-8 item data. This can be done for example by querying the SQL : SET NAMES 'UTF8'
An HTML form with utf-8 charset is stored TO a mysql db (in linux and windows)
then the form is filled FROM that DB, and surprise!
the ó simbol I've stored becomes an ugly �
Any idea of what can be happening?
I've configured my.ini default-character-set=UTF8, the same with php.ini with default_charset = "utf-8"
I've added <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
to the HTML
I've tried to use php iconv function, utf8_encode, configured collation to utf8...
I don't know what is happening with the utf8, thanks for any advice
Does the varchar or text field used to store the value have a collation from the utf8 group (such as utf8_unicode_ci) If not, chances are your string is being stored in a single-byte character collation, giving you the bad result.
I'm looking for a help with encoding problem I've been struggling for couple days now already.
I have a database with Collation "latin1_swedish_ci". When I view a single entry it shows a messed up text
grieþos informçs
it should be
griežos informēs
Ok so... I tried to output text into browser with php script and set
<meta http-equiv="Content-Type" content="text/html; charset=windows-1257" />
Now... it shows data correctly ("griežos informēs"). What I need to do is convert this data to UTF-8 so I can use
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and get everything displayed correctly.
I tried to use Notepad2 and create a file with encoding windows-1257 then copy text from database and save it.... same problem.
Tried to even create a table in that database with utf-8 collation and insert data there... no luck - just shows ? where special chars should be.
Any help would be appreciated,
Thanks
SELECT CAST(_cp1257_general_ci'test' AS CHAR CHARACTER SET utf8);
(test is the column name)
That will get you the row in the proper character set. You should create a new table using UTF8 then SELECT CAST(....) FROM old_table INTO new_table
You may also want to change the character set of the old table to cp1257_general_ci instead of latin1_swedish_ci.
In order to do it without losing data first change the datatype of the column to blob, then change it a second time to varchar with the cp1257_general_ci, then finally a third time to utf8_unicode_ci (I suggest a backup first, just in case.)
Use this query right after you open your connection to your database so you run it once on every page load :
mysql_query('SET NAMES `utf8`');
am using MySQL version 5.1.49 and I have not enabled UTF8 character encoding. The default character-set for MySQL is latin1. How can I change it show UTF8 characters?
Even when I query a table using Workbench I get 'NULL' in name section which I want, should display mutibyte characters.
ALTER DATABASE DEFAULT CHARACTER SET utf8
and for each table:
ALTER TABLE SomeTableName DEFAULT CHARACTER SET utf8
also if you will be viewing them from a webpage the HTML need this:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
and if you are using PHP, use htmlspecialchars() to display the values like this:
echo htmlspecialchars($row['some_field'], ENT_COMPAT, 'UTF-8');
and (again only for PHP) do this after mysql_connect():
mysql_query("SET NAMES 'utf8'");
I have a multilingual site and I am having a problem inserting Chinese meta tags. These are transformed into question marks.
Is there a way how I can achieve this?
Many thanks
--EDIT--
The table storing the SEF Urls is in the latin1_swedish_ci character set. How can I change this single table to utf8_general_ci without breaking the URLs?
Many thanks!
Make sure that:
The character encoding you are using includes those characters (UTF-8 is safe)
Your editor is configured to use that character encoding
Your database (if these details are stored in one) is configured to use that encoding
Your webserver is configured to output a charset parameter on the Content-type header (and it uses the correct encoding)
Your browser is not configured to ignore the specified encoding
Use numeric character references.
EDIT
wiki numeric character references
Convert Chinese characters to Unicode
Are you retrieving the data from a database?
If so ensure that you connection character set is also set to utf-8.
In MySQL for example you would need to issue this query before any other:
SET NAMES 'utf8';
It could be that you need to encode the Chinese characters to HTML entities, or specify a character set.
Have you checked your character set in your document headers? I usually use UTF-8 to achieve chinese character sets.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
If you're using a program like dreamweaver, make sure your files are actually being SAVED in the correct character set as well. We had a problem where characters in a dreamweaver file were coming through as ???? because the editor itself was set to iso-8859-1
Maybe your Browser - or more exactly, the font you selected to display the page - doesn't support chinese characters. What system and browser is this on?