Reputation: 17530
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 difference 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
Upvotes: 2
Views: 596
Reputation: 2057
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" />
Upvotes: 1
Reputation: 799470
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.
4: UTF-8.
Upvotes: 10