Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 753619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:55:06+00:00 2026-05-14T14:55:06+00:00

I am trying to store a list of countries in a mySQL database. I

  • 0

I am trying to store a list of countries in a mySQL database.

I am having problems storing (non English) names like these:

  • São Tomé and Príncipe
  • República de El Salvador

They are stored with strange characters in the db, (and therefore output strangely in my HTML pages).

I have tried using different combinations of collations for the database and the MySQL connection collation:

The “obvious” setting was to use utf8_unicode_ci for both the databse and the connection information. To my utter surprise, that did not solve the problem.

Does anyone know how to resolve this issue?

[Edit]

It turns out the problem is not to do with collation, but rather encoding, as pointed out by the col. I notice that at the command line, I can type two separate commands:

SET NAMES utf8

followed by

[QUERY]

where [QUERY] is my SQL statment to retrieve the names, and that works (names are no longer mangled). However, when I do the same thing programatically (i.e. through code), I still get the mangled names. I tried combining the two statements like this:

SET NAMES utf8; [QUERY]

at the command line, again, this returned the correct strings. Once again, when I tried the same statements through code, I got wrong values.

This is a snippet of what my code looks like:

$mysqli = self::get_db_connection();
$mysqli->query('SET NAMES utf8');

$sql = 'SELECT id, name FROM country';

$results = self::fetch($sql);

the fetch method is:

    private static function fetch($query)
    {
        $rows = array();

        if (!empty($query))
        {
            $mysqli = self::get_db_connection();

            if ($mysqli->connect_errno)
            {
                self::logError($mysqli->connect_error);
            }
            else
            {
                if ($result = $mysqli->query($query))
                {
                    if(is_object($result)){
                        while ($row = $result->fetch_array(MYSQLI_ASSOC))
                            $rows[] = $row;
                        $result->close();
                    }
                }
            }
        }
    return $rows;
    }

Can anyone spot what I may be doing thats wrong?

Just to clarify, the HTTP headers in the page are set correctly
‘Content-type’: ‘text/html; charset=utf-8’

so thats not the issue here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:55:06+00:00Added an answer on May 14, 2026 at 2:55 pm

    As a matter of fact, collation affects nothing of a kind. it’s a thing used for ordering and comparison, not recoding.
    It is encoding responsible for the characters itself.

    So, your problem comes not from the table collation but from the connection encoding

    SET NAMES utf8
    

    query should solve the problem, at leas for the newly inserted data

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to store an array list in session like so: private Map session
I'm trying to use an array to store a list of file names using
I'm trying to store routes in database, and list those based on parameters. Kinda
Im trying to store a list,collection of data objects in Hbase. For example ,a
I'm trying to store a List as a DynamoDB attribute but I need to
I have a need to store an ordered list of strings and am trying
I'm trying to store an image into an SQL database without using temporary files.
I'm trying to store a list of generic objects in a generic list, but
hello mates i am trying to store value from dropdown list to an integer
I am trying to allocate a block of memory, and store a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.