Hope4You
Hope4You

Reputation: 1957

PHP/Mysql Character Sets

I have a PHP/MySQL application, where it needs to work with UTF-8 characters behind-the-scenes (the UTF-8 characters won't be shown on-screen). The UTF-8 characters are from a PHP cURL request.

What do I need to do to make PHP and MySQL properly function with UTF-8 characters?

  1. Do I need to set default_charset = utf-8 in php.ini? Or is this only used when data is displayed on-screen?

  2. Do I need to set the character set/collation to utf8/utf8_general_ci for my databases, tables, and columns?

  3. I read that there's also a such thing as connection character sets for MySQL. Does this really matter?

  4. Is there anything else I need to do?

Thanks for the help.

Upvotes: 0

Views: 443

Answers (2)

martinstoeckli
martinstoeckli

Reputation: 24151

Consider to use UTF-8 for everything, the php files, the HTML encoding and the database, it will save you a lot of troubles. You won't need to convert between encodings, you can use all possible characters of all encodings, and you can do without HTML entities.

I collected some tips of how to make your site UTF-8 only. Should you already have a database in a different encoding, that's no problem, just tell the connection object to deliver UTF-8.

$db = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);
$db->set_charset('utf8');

Upvotes: 1

Amar Gharat
Amar Gharat

Reputation: 154

You can use following php in-built functions to iso characters to utf8 charset

utf8_encode(CHARACTERS);

Upvotes: 0

Related Questions