Unicode font like arabic or others displaying technique on webpage from mysql database at CakePHP or raw php


1. Make Sure that your database has UTF8 Character set, Run the following code

 ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 

2. Make Sure that your table has UTF8 Character set and Collate utf8_unicode_ci or utf8_general_ci

 ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 

3. Make Sure that your webpage has utf8 enable

 <meta charset="UTF-8">
 

4. Set utf8 before any mysql query in raw php

 mysql_query("SET NAMES utf8");
 

At CakePHP you can set this very easily at database config file:

Remove the comment line before ‘encoding’ and make this line available for execution.

 
 public $default = array(
	'datasource' => 'Database/Mysql',
	'persistent' => false,
	'host' => 'localhost',
	'login' => 'root',
	'password' => '',
	'database' => 'cake278',
	'prefix' => '',
	//'encoding' => 'utf8',
 );
 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s