Codeiginter mysql storing chinese characters as questions marks - mysql

When I type in chinese characters to store in the database, it becomes ??? question marks instead.
Anyone can help me with this?
My codeigniter config settings for char set is
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_unicode_ci';
my meta tag is as below as well
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

This issue occur when you have not set the table charset to utf8. Check your table and set its Chartset to utf-8 and collation to utf8_general_ci or utf8_unicode_ci (which is best for your language :) ).
This will fix the issue.
Thank you

Related

MYSQL name field not taking name in other languages

I have this field
display_name varchar(30) latin1_swedish_ci
it takes English names as usual, but this database deals in different languages, and also users from all around enter there names, some of which are in different languages. french lets say, and a name stored in french is displayed like this ???????
what could be the reason? i believe it has something to do with this latin1_swedish_ci how can i make this field generic to take and display any name in any language correctly?
You need to call:
mysql_set_charset("utf8");
Also refer: 10.1.10 Unicode Support
Or the other way is to use utf-8 in MYSQL by adding this to your my.cnf:
collation_server = utf8_unicode_ci
character_set_server = utf8
and when you are executing your query the first use these two queries:
SET NAMES 'utf8';
CHARSET 'utf8';
if php code for connect to mysql,add code to (class mysql or code):
$dbLink = mysql_connect($argHost, $argUsername, $argPassword);
mysql_query("SET character_set_results=utf8", $dbLink);
and add code in meta tag to html code in head :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
======================================================================
or
To set the default to UTF-8, you want to add the following to my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

MYSQL - Turkish character

I retrieve datas from mysql
This is normally which i have in db
This is normally i have in db
Seçimler, Şirketler ve Siyasi Partiler
it prints
Se�imler, ?irketler ve Siyasi Partiler
I use sql yog and change some preferences in my db
i set Charset to UTF8 and Collation is utf8_turkish_ci
but still retrieve datas like that
Se�imler, ?irketler ve Siyasi Partiler
why? What's the problem ?
this problem sounds like you've missed to specify a character encoding somewhere. to solve this, simply make sure you've set character encoding to utf-8 everywere (it doesn't actually need to be utf-8, just the same everywhere - but if you've messed up something and need to change some places anyway, i'd strongly recommend using utf-8):
tell MySQL to use utf-8. to do this, add this to your my.cnf:
collation_server = utf8_unicode_ci
character_set_server = utf8
before interacting with mysql, send this two querys:
SET NAMES 'utf8';
CHARSET 'utf8';
or, alternatively, let php do this afteropening the connection:
mysql_set_charset('utf8', $conn);
set UTF-8 as the default charset for your database
CREATE DATABASE `my_db` DEFAULT CHARACTER SET 'utf8';
do the same for tables:
CREATE TABLE `my_table` (
-- ...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
assuming the client is a browser, serve your content as utf-8 and the the correct header:
header('Content-type: text/html; charset=utf-8');
to be really sure the browser understands, add a meta-tag:
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
and, last but not least, tell the browser to submit forms using utf-8
<form accept-charset="utf-8" ...>
You need to mention Charset to UTF8 in your selection query too.
SET NAMES 'utf8';
CHARSET 'utf8';
What made the difference for me was to add these lines:
collation_server = utf8_unicode_ci
character_set_server = utf8
to my.ini file (at the end of the document) I have tried everything else but they all failed until I made this change. It's really been a great help. Thanks oezi.
I added
$this->db->exec("SET NAMES 'utf8'");
in connection
and added
charset utf8 to my procedure parameters
Sample
PROCEDURE `up_users`(IN `lid` INT, IN `lfirstname` VARCHAR(100) CHARSET utf8, IN `llastname` VARCHAR(100) CHARSET utf8, IN `lstatus` VARCHAR(1) CHARSET utf8, IN `lpassword` VARCHAR(255) CHARSET utf8)

UTF8 lost in translation, HTML form from/to mysql

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.

Mysql charset and form

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.

How to configure mysql version '5.1.49-1ubuntu8' to show multibyte charecters?

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'");