1

I have two servers. Each runs PHP/MySQL. I paste a 6-character string from my clipboard into newly created tables in both databases. Inspection of the table column shows that the charset and collation are set to "utf8" and "utf8 general ci" on both servers. I then run the following identical script on both servers.

<meta charset="utf-8">
<?php
$sql = "SELECT * FROM temp";
$link=mysqli_connect($DB_SERVER,$DB_LOGIN,$DB_PASSWORD,$DB);
$result=mysqli_query($link,$sql);
mysqli_close($link);
$row=mysqli_fetch_object($result);
$details=$row->details;
echo $details;
?>

One server sends the following to the screen

‘good’

the other sends this to the screen in the same browser (Firefox)

‘good’

Can anyone spot the problem or suggest how I can troubleshoot this?

wurzel_gummidge
  • 287
  • 2
  • 11
  • How do you get the data *into* mysql? characters can also get mangled on the way in. You say that you copy it from your clipboard, but it has to be more complicated than that: what program are you using to actually get the data into mysql? This obviously doesn't fix your problem, but just to point out, the only reason mangling is possible in the first place is because your single quotes aren't actually single quotes but rather unicode characters, most likely U+2018 and U+2019 – Conor Mancone May 26 '17 at 19:23
  • I would check both databases directly to see what the database says is in there (using mysql from the command line preferably). If you see the same in both then the characters are probably getting mangled on output. If one has a different result stored then your characters are getting mangled on input. – Conor Mancone May 26 '17 at 19:25
  • See "Mojibake" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James May 27 '17 at 03:17

1 Answers1

2

Problem:

The browser misinterpretes the encoding.

Possible causes:

  1. You didn't specify the encoding of the mysqli connection, use mysqli::set_charset()
  2. You did not specify HTML 5 doctype <!DOCTYPE html> that enables Unicode (UTF-8)
  3. Another encoding was specified in the HTTP-header
  4. The webserver serves the page with another encoding and overrides header()
  5. Without configuration, one PHP instance may be configured differently compared to the other instance.
  6. If not configured one PHP instance may be of an older version before 5.6, which does not have UTF-8 configured by default.
  7. Data is pasted differently into the two databases, you might want to double check.
Code4R7
  • 2,600
  • 1
  • 19
  • 42