MYSQL DB not showing uft8 on php page

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
aie8
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Jan 12, 2020 11:29 pm

Tue Jan 14, 2020 8:34 am

Hello everyone,
I created a database and a table. I created a php page. When I visit the php page, the foreign characters change to question marks. This is what I did to troubleshoot:

1- php page contains the tag: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2- I tested that the problem is with the mysql db by adding text directly on the php page, and it was showing correctly. So it's not the php page not uft enabled.
3- mysql db is using MyISAM utf8_general_ci
4- When I go to the table inside the db, I see the text displayed correctly.
5- When I test using the my localhost, everything works perfectly. When I add it to Bluehost server, I get the ???? instead of the actual characters.

What am I missing? Thanks!
chorn
php-forum GURU
php-forum GURU
Posts: 630
Joined: Fri Apr 01, 2016 2:18 am

Thu Jan 16, 2020 12:11 am

Did you check the file beeing UTF8 WITHOUT BOM? How do you transfer files? FTP may change the encoding, you can try binary transfer.

Did you try setting SET NAMES statement on database connection?
aie8
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Jan 12, 2020 11:29 pm

Mon Jan 20, 2020 9:23 am

I tried this and it worked:
mysql_select_db("datab1");
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8');
chorn
php-forum GURU
php-forum GURU
Posts: 630
Joined: Fri Apr 01, 2016 2:18 am

Wed Jan 22, 2020 2:14 am

You should change to MySQLi - or better PDO - soon, the mysql_* functions are deprecated and are already removed in current versions of PHP 7. It looks like you are using PHP 5.x which is outdated:

https://www.php.net/supported-versions.php

https://www.php.net/manual/en/book.pdo.php
Post Reply