charset in MySQL
I'm developing a blog in MySQL, everything will be in English and will contain some special characters like
`,~,!@#$%^&*()_+=-[]{};'\:"|,./<>?/*-+
Q1-> Which charset i should use [and why] ?
Q2-> what is the differe开发者_开发技巧nce between UTF-8/16/32 and Latin1 ? Q3-> Does UTF-8 uses less space than those ? Q4-> Which charset to use to support bengali ?[When i want to save ' in my DB it convert it to ‘ which is really boring :x]
MySQL 5.5.8 and PHP 5.3.3
1: UTF-8, since any character you care about will only take a single byte, plus it can be expanded if in the future you have characters not found in that.
2+3: "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)"
4: UTF-8.
You can use charset=ISO-8859-1 if you have English and those symbols you mentioned. If you are going to use Bengali you need UTF-8.
define('SQL_HOST','databasehost');
define('SQL_USER','user');
define('SQL_PASS','password');
define('SQL_DB','databasename');
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
or die('Could not connect to the database; ' . mysql_error());
mysql_select_db(SQL_DB, $conn)
or die('Could not select database; ' . mysql_error());
mysql_query("SET NAMES 'utf8'");
Using mysql_query("SET NAMES 'utf8'");
takes care of UTF-8. I think it will work for Bengali, as it worked for Devanagari in my case.
Do not forget to mention the same encoding in the meta
tag
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
精彩评论