Can't insert šđčćž chars into MySQL database via PHP

My host changed the server from Windows to Linux and the problems started.

The problem is with “special characters” like šđčćž and inserting them into the database.

First problem, which I solved was that the existing data (usernames) were not displayed as they should it they contained special chars.

This was solved by inserting the following code into the PHP:

$mysqli->query(“SET NAMES ‘utf8’”);

Now the problem is when I try to insert the šđčćž into the database.

The text is entered into the Corona native.newTextField and here it shows OK.

Then I call the PHP with this:

params.body = “playerName=” … me.username

network.request(PHP_URL_SELECT_LEADERBOARD, “POST”, networkListenerGame2, params)

The database collation is utf8_general_ci.

Tried to add this

$mysqli->set_charset(‘utf8’);

but doesn’t help.

Please help!

P.S. It worked perfect while the db was on the Windows server

i resolved my problem after adding this:

$conn = new PDO("mysql:host=$host;dbname=$db\_name;charset=utf8", $username, $password);

the part i added is:

charset=utf8

after the database name.

Thank you very much for trying to help.

Unfortunately, I do not use PDO.

Here is what I tried, I guess that should be the same:

$mysqli = new mysqli($host, $username, $password, $db_name);

if ($mysqli->connect_errno)

    {

    echo “Failed to connect to MySQL: (” . $mysqli->connect_errno . ") " . $mysqli->connect_error;

    }

$mysqli->query(“SET NAMES ‘utf8’”);

$mysqli->set_charset(‘utf8’);

That does not help :frowning:

I am so sorry, I was executing the wrong PHP :frowning:

After adding 

$mysqli->set_charset(‘utf8’);

it works.

Regards,

Damir

good to know you solved your problem :slight_smile:

i resolved my problem after adding this:

$conn = new PDO("mysql:host=$host;dbname=$db\_name;charset=utf8", $username, $password);

the part i added is:

charset=utf8

after the database name.

Thank you very much for trying to help.

Unfortunately, I do not use PDO.

Here is what I tried, I guess that should be the same:

$mysqli = new mysqli($host, $username, $password, $db_name);

if ($mysqli->connect_errno)

    {

    echo “Failed to connect to MySQL: (” . $mysqli->connect_errno . ") " . $mysqli->connect_error;

    }

$mysqli->query(“SET NAMES ‘utf8’”);

$mysqli->set_charset(‘utf8’);

That does not help :frowning:

I am so sorry, I was executing the wrong PHP :frowning:

After adding 

$mysqli->set_charset(‘utf8’);

it works.

Regards,

Damir

good to know you solved your problem :slight_smile: