The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 09:13:40 PM

Login with username, password and session length


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

Posts: 5627


Back in my day we had 9 planets


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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


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

to quote martha. "it's a good thing."
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
DangerMouse
Expert
****
Offline Offline

Posts: 244



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
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
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

No links in signatures please
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
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!