The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. January 08, 2009, 01:37:54 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: UTF-8 from php, problems, and a solution.  (Read 734 times)
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« on: February 23, 2008, 11:58:53 AM »

I have been having lots of issues with character encodings for some reason. I am still having a regex problem, and was until just now, having a mysql storage issue.

I have the tables set to a charset of utf8 and colation of utf8-general-ci
You would think this would work, but oh no...
Chars still get stored as funky combos of extended characters. like "don’t" getting stored as "don’t".
apparently the problem comes from the connection. The connection actually needs to be UTF8. go figure...

so, all you need to do is add this right after your database connection in PHP, but before you do anything of value with the DB.
mysql_query("SET NAMES `utf8` COLLATE `utf8_general_ci`")

you can do this from some file settings or ini files, but, you may not have access to that stuff. I generally prefer to set stuff from runtime, since I may not know what environment my stuff might run under. A little loss of efficiency, for complete portability is my general rule.

I wanted to post this, because it drove me nuts, and someone else might benefit from the solution.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5324


:sniffle: Humor was so much easier before.


View Profile
« Reply #1 on: February 23, 2008, 12:57:25 PM »

Beauty NBs, thanks - I get troubles with that stuff occasionally as well but haven't taken the time to figger it out.  Praise
Logged

If I can't be Mr. Root then I don't want to play.
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« Reply #2 on: February 23, 2008, 01:34:34 PM »

to quote martha. "it's a good thing."
Logged
DangerMouse
Expert
****
Offline Offline

Posts: 177



View Profile
« Reply #3 on: February 23, 2008, 03:03:59 PM »

The UTF-8 default character encoding thing will be the best part of PHP6 I hope.

DM
Logged
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« Reply #4 on: February 23, 2008, 05:48:06 PM »

i think so as well. especially since I seem to be finding every single issue with UTF under mysql 5 and php5 lol.
Logged
webguy332
n00b
*
Offline Offline

Posts: 7


View Profile
« Reply #5 on: February 26, 2008, 06:52:23 PM »

Will the upgrade to php6 be worth the headaches?
Logged
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3525


View Profile
« Reply #6 on: February 26, 2008, 07:21:57 PM »

probably not until after a few point releases. but for built in utf8, i might be an early adopter...
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!