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: 5
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: 653
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: 5
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: 653
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
aie8
New php-forum User
New php-forum User
Posts: 5
Joined: Sun Jan 12, 2020 11:29 pm

Tue Jan 28, 2020 9:54 pm

How do I convert the above code to a non deprecated code? Thank you!
chorn
php-forum GURU
php-forum GURU
Posts: 653
Joined: Fri Apr 01, 2016 2:18 am

Tue Jan 28, 2020 11:35 pm

You read the docs provided, start making your connection and perform the queries.
aie8
New php-forum User
New php-forum User
Posts: 5
Joined: Sun Jan 12, 2020 11:29 pm

Tue Feb 04, 2020 8:15 pm

I looked at the links provided. I can't find the answer there or at least not that it was straight forward. All I need is to fix the connection to be more up to date. I was hoping not having to learn a whole language just to update a deprecated code. I appreciate your help though.
Post Reply