Avatar of eurocoptersea
eurocoptersea
 asked on

What is the "best practice" for choosing character encoding with PHP/MySQL applications?

Dear All:

May i know what is the "Best Practice" character encode if my application is open to world wide?

How should i make sure that the system and database is capture and store the information for all type of charset that user input?


Thank you.
PHPMySQL ServerApache Web Server

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Loganathan Natarajan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Loganathan Natarajan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
eurocoptersea

ASKER
I set my PHP default charset = utf 8, database table (Collation) = 'utf8_unicode_c'.

does this good enough?  or i need to using php function to convert all "POST" data to utf8?

Thank you,
Loganathan Natarajan

SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
eurocoptersea

ASKER
thanks. Any quick way to implement? apache web server setting?

cause we have about ten application. if added for each pages may be need a lot of time and resources.

thank you.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Loganathan Natarajan

You suppose to stored the encoded strings texts in the tables from database... so it will display properly.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
eurocoptersea

ASKER
current i the charset for my database was "latin1_swedish_ci", if i change it to "utf8_unicode_ci", will it cause any problems?
Loganathan Natarajan

I am not sure whether it will set for existing table data. As I tried, it does not work one of my project. you could check that.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
eurocoptersea

ASKER
Yes, logudotcom.....it will not convert the data you have stored in the table but i just worries whether will it be missing any information if i changes it directly.
neoxium

You have to set UTF-8 all along the process :

- At coding time, set your IDE to encode files with UTF-8.
- For browsers, meta charset of HTML files have to be UTF-8 (data sent to server will be UTF-8 encoded)
- Create database schema and tables using UTF-8 for charset and collation
- And finally, (thing people often forget) set the database connection to UTF-8, you can do it in your scripts at database initializing, the very first query :

SET NAMES UTF8

or

SET CHARSET UTF8

And your done.
Ray Paseur

No points for this, but the background information is explained here:
http://www.joelonsoftware.com/articles/Unicode.html
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy