How to Make Rails and PHP Apps Fully UTF-8 Compliant with MySQL

Every web programmer knows that UTF-8 is where it’s at these days. Even if you are coding something for only the US market, you’re still probably going to run into names, addresses, or whatever with accented characters.

Everyone knows that “all you have to do” is make your app speak UTF-8, set the character encoding in your web pages to UTF-8, and set your database encoding and collation to something like utf8_unicode_ci, and you’re off and running… right?

Not quite. You’ve probably run into the situation where you hop into phpMyAdmin and edit some table row, and what to your wondering eyes should appear, but something like this:

Voici un article français.

Well, crap. That’s supposed to be a “ç” in “français”, not an “ç”!

And yet, when you view the web page and edit the content in your app, it looks and works fine! What’s going on here?

It’s really quite simple, and apparently something that no one bothers to mention: you have to tell your app to communicate with the database in UTF-8! Here’s how you do that in PHP and Rails

(more…)

The Easy Way to Copy a MySQL Database

MySQL Database CopyIf you have a web site of any kind, you probably have dealt with MySQL databases. Sometimes, you need to move your database, whether it’s to another server or back onto your existing server after performing an OS upgrade.

The advice you usually hear goes like this: Export the table structure and data using the mysql command line utility or with phpMyAdmin. Then reimport the exported data once your install/upgrade is done.

Well, that’s just a serious pain in the arse.

Lucky for you, there’s a very, very easy way to copy your DB over with a few copy commands…

(more…)