Welcome Guest, Not a member yet? Register   Sign In
UTF 8 support for CodeIgniter
#1

[eluser]Phil Sturgeon[/eluser]
After answering a few questions on the subject recently, I felt it would be a good topic for a new post.

"UTF-8 support for CodeIgniter"

Sadly, this It seems like David Behler felt it was a good topic too and rushed out an article on the same topic after seeing my tweet.

Read them both and decide who's you like the most.

And no, my lack of syntax highlighting doesn't count. That feature is on the way. ;-)
#2

[eluser]davidbehler[/eluser]
Yeah...well I'm kinda sorry for stealing your topic.

Next time I got a good idea I'll tell you first so that you can steal it from me...that should make use even again Big Grin
#3

[eluser]Phil Sturgeon[/eluser]
Haha! Deal. :coolsmile:
#4

[eluser]jedd[/eluser]
Hmm .. not something I've looked at before, but realise that one day I'll have to attend to this problem.

Why doesn't the CREATE / ALTER DATABASE with the DEFAULT COLLATE and DEFAULT CHARACTER SET not suffice - why do you need to add those defaults back onto each table you create too? This seems horribly messy (I like clean create.mysql scripts Wink
#5

[eluser]InsiteFX[/eluser]
Hi jedd,

You do not have to add them back here is how to hadle it.


The World Wide Web uses UTF8 for database collation.

All of us shoud being using UTF8 for our database's.

I moved one of my sites to a new host stepped into the MySQL Hell weird characters etc.

using phpMyAdmin

The collation problem will only show up if you creat a new databse and table!

Click on the database you created in the left menu. This will only work if your table was created with a
PRIMARY KEY.

Now look on the sturcture of the database on the bottom ( MyISAM INDEXES ).
See the collation is wrong, default is latin1

To change your MySQL database collation.

Usually you will be interested in changing your MySQL collation in order to solve problems with foreign character encodings. One of the most common case is to change your MySQL collation from latin1 to utf8. This can be done by
using phpMyAdmin and following these instructions:

1. Enter your cPanel and click on the phpMyAdmin icon in the Databases left menu.

2. Select the database you wish to manage and chage your collation for from the
menu on the left, this maybe a dropdown combo box.

3. Click on the Operations tab in the top menu of your phpMyAdmin.

4. At the bottom of the page you will see the collation option. You can now select and change your database
collation from the drop down menu and then click on the Go button.

NOTE: you should select utf8_general_ci

Please NOTE: That after you change the collation of your database, only the new tables that you create will be
set to the new collation. All other tables will remain the same with the collation that they were initially
created with.

Most of the Web Hosts have set MySQL's collation to utf8 by default for their customers.
You can also benefit from this feature.

Also when you start creating your new tables you shold add this line to the bottm.

CREATE TABLE IF NOT EXISTS `your_table_name` (

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

Use which ever database you want here, just make sure you use the CHARSET=utf8 and COLLATE=utf8_general_ci you can also use utf8_unicode_ci

this will keep you out of MySQL Hell! If you ever need to transfer your database's.


Enjoy
InsiteFX
#6

[eluser]jedd[/eluser]
Thanks for the reply there - I don't use phpmyadmin all that often, but it's handy when I don't want to remember the various CLI interrogation commands within MySQL.

But my question still stands - if you create your database with the default charset and collation, you don't need to set that in all the subsequent create table commands, right?

Both tutorials seemed to imply you do.

I guess it's good coding practice to make this explicit in your scripts, but as I say, I don't like the aesthetics of that, or the inherent redundancy.
#7

[eluser]Phil Sturgeon[/eluser]
UTF-8 support techniques seem to have a great deal of redundancy. Theoretically speaking if you set output as UTF-8 via Apache then it should mean that there is no need to set it in the HTML too, but that does not work for all situations. Some browsers do not interpret it properly, etc.

I just find that setting it in EVERY damn place you can find is the safe bet. I originally just had it set as the database default but strange things kept on happening so now I just spam the hell out of UTF-8 support just to make sure.

This was mostly a list of every place in which the setting can exist, so other users can spam it too. :-)
#8

[eluser]davidbehler[/eluser]
What he said! xD

No, serioulsy.
If you define the default char set and default collate for the database, then you should not have to define it again for the tables/columns. But you never know Wink

Depending on the software you/your users are using some crazy stuff can happen and it's definetly a good idea to set UTF-8 wherever you can!




Theme © iAndrew 2016 - Forum software by © MyBB