Skip to content
Advertisement

Character encoding issue with PHP/MySQL

I have a web application I have been developing locally on my computer, I have recently launched it on my web server with the exact same settings for MySQL, but for some reason I am encountering a character encoding issue where “smart quotes” (’) are being displayed as black triangles with question marks (�), but only on the server.

This is on the HTML:

JavaScript

My local MySQL database (without character issues) is MySQL 5.7.26 with an InnoDB table with UTF8MB4 encoding and a table collation of utf8mb4-unicode-ci

My server MySQL database (with character issues) is MySQL 5.5.5-10.3.21 with an InnoDB table with UTF8MB4 encoding and a table collation of utf8mb4-unicode-ci

Perhaps there is a PHP setting somewhere I am missing?

Edit:

if I run this script on my computer is works perfectly, but if I run the same script on my server with the same data in the database, it give me the character encoding issue:

JavaScript

Advertisement

Answer

(Since this clearly shows a PDO omission, I am reopening)

One-line change:

JavaScript

References:
http://mysql.rjweb.org/doc.php/charcoll#php
Trouble with UTF-8 characters; what I see is not what I stored (Look especially for “black diamond”.)

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement