Diagnosing the root of the issue.
I am having problems making mydatabase table show Latin caracters.
This has all of the signs of an encoding mismatch between your HTML form data, the PHP file and the MySQL. My guess is the issue is your HTML form and the PHP file are sending UTF8 data—since UTF8 is the default encoding method nowadays—to the MySQL database which is setup (by default) to use
So this is one of those “six of one, half a dozen of another” issues where you could theoretically change the encoding in the HTML and PHP file to be
latin1_swedish_ci. But that is pretty regressive in today’s Internet world and the world of web development.
So I would recommend making sure your whole data chain—from the HTML form to the PHP to the MySQL database—is all UTF8. Once you get everything in UTF8, life is tons easier for tons of reasons.
As for why you are seeing this issue is because (by default) most MySQL installs set
latin1_swedish_ci instead of
utf8_general_ci for newly created databases. So you’re on the right track in your attempts to fix that.
But there is more than one thing you need to do to get a MySQL database—and datives server—set to properly handle character encoding and—in this case—UTF8 encoding.
Steps you can take to resolve the issue.
First, change the collation of the database and try again.
ALTER DATABASE [name of your database] CHARACTER SET utf8;
If this is a specific table, the collation can be changed as so:
ALTER TABLE [name of your table] CONVERT TO CHARACTER SET utf8;
And if it is a specific column in a table:
ALTER TABLE [name of your table] MODIFY [name of your column] [other settings] CHARACTER SET utf8 COLLATE utf8_general_ci;
Or perhaps you could export the current database, create a new database with this command & reimport the data:
CREATE DATABASE [name of your database] CHARACTER SET utf8 COLLATE utf8_general_ci;
And if you want to make a permanent change to the MySQL install on the machine giving you an issue, go and edit
my.cnf. The following would set the whole chain to UTF-8:
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8