Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with utf-8 encoding using PHP + MySQL

Tags:

I moved data from MySQL 4 (they were originally set to latin2 encoding) to MySQL 5 and set the encoding to UTF-8. It looks good in phpMyAdmin, and UTF-8 is okay. However, there are question marks instead of some characters on the website! The website encoding is also set to UTF-8, so I don’t understand where the problem is.

PHP and HTML files are also set to UTF-8.

How can I fix this?

like image 790
Adriana Avatar asked Nov 10 '09 13:11

Adriana


People also ask

How do I make MySQL handle UTF-8?

To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.

Does PHP support UTF-8?

PHP | utf8_encode() FunctionThe utf8_encode() function is an inbuilt function in PHP which is used to encode an ISO-8859-1 string to UTF-8. Unicode has been developed to describe all possible characters of all languages and includes a lot of symbols with one unique number for each symbol/character.

Does MySQL support UTF-8?

MySQL supports multiple Unicode character sets: utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four bytes per character. utf8mb3 : A UTF-8 encoding of the Unicode character set using one to three bytes per character.

What is UTF-8 PHP?

Definition and Usage. The utf8_encode() function encodes an ISO-8859-1 string to UTF-8. Unicode is a universal standard, and has been developed to describe all possible characters of all languages plus a lot of symbols with one unique number for each character/symbol.


1 Answers

Try the query

SET NAMES utf8

before any query in your application.

like image 162
Valentin Golev Avatar answered Oct 07 '22 23:10

Valentin Golev