3

I have a database that has the names of players (it's stats db for game), but when i fetch the player names with mysqli query i'm getting some wierd results.

For example the characters "Α†Ω" are displayed as "?�?".

  • When i open the table in phpmyadmin the characters are displayed correcly
  • html content type is utf-8 (i even copied the meta from phpmyadmin just to be sure.)
  • the database and it's tables are utf8_general_ci

What can i do to display these (and other) characters correctly?

4 Answers 4

5

You have to set the connection charset to utf8.

Execute the following function: http://php.net/manual/en/mysqli.set-charset.php

Or execute the following query:

 SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8
Sign up to request clarification or add additional context in comments.

Comments

3

While fetching the result at the client side from database. You have to specify about connection charset. So it is better to mention charset in the mysql config file. After successful connection, write the following code line:

mysqli_set_charset($con,"utf8"); // Change character set to utf8

Comments

1

With mysqli you would have to run this code after you made the connection:

mysqli_set_charset($conn, "utf8");

Comments

0

You need to set the charaset for the connection from php. Put the following code after connecting to the database.

mysql_query("SET NAMES utf8");

That is if you are using mysql ext.

2 Comments

I'm sure this would have worked to, but i was using mysqli. But thanks :)
mysql_query has been deprecated as of PHP 5 and deleted entirely as of PHP 7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.