Search code examples
phpmysqlshared-hosting

how to convert latin1 charset client-sent character to utf8mb4


I host my website on iPage shared hosting. I do not have root privileges so i cant configure mysql enviroment variables. that particulat variables are these

those vars

when i try to pull data (i.e. text containing these characters: čćžšđ) from the database that are not from latin1 charset i get ? rendered on my website, but on my localhost xampp server (where these variables are utf8mb4 instead of latin1) no problems occur

reminder: this database's collation is utf8mb4_general_ci, and mentioned characters ARE PROPERLY STORED, only when retreiving data the problem occurs

since I cant change these variables (shared hosts dont get root privileges, in this case mysql SUPER privilege) i need a workaround, any suggestions?


Solution

  • Use SET NAMES utf8mb4 to set the client & connection character set. You can do this as a session setting immediately after you connect. You don't need global privileges to do this.

    Some connectors even provide a built-in way to do this, so check the documentation for the connector you use.