views:

24

answers:

1

I've converted my database from Latin 1 to UTF8, and using phpPMyAdmin you can enter data and display it correctly. However viewing in the pages I've developed in PHP and editing it using my simple CMS saves characters that must be incorrectly coded.

I've spent a few hours researching and eventually came up with this code snippet:

mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn_products);

Which when placed before a DB operation corrects the issue - marvellous!

I've done some further research, and have (I believe) discovered a way to make this permanent across an entire MySQL Server, but I would like to permanently change it per database as a majority of the sites using the server are Latin 1, and need to stay that way.

Can anybody point me in the right direction please?

+2  A: 

You cannot do it per-database unfortunately, it's either set by the client application or the server if a client doesn't state anything. You only have to set it once per session, so just teaching yourself to let a always follow up a mysql_select_db() that is probably there be with mysql_query('SET NAMES utf8;') (or whatever character set you need) should do the trick.

Wrikken