This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 6 years ago.
I recently upgraded my site to PHP 5.7 and a new install of the MySQL database. The previous data was imported.
Now I have a lot of the question marks in diamonds in outputted text. I have read up, and the problem seems to be that the collation of my database is set to latin1_swedish_ci and I need to be utf8 to correctly render special characters stored in the database.
If I change the collation will this potentially solve my problem, fixing the older postings?
Do I switch off the site before changing the collation, and does it require a reboot to take effect? I'm a little nervous about corrupting the data as my users would be extremely upset to lose their historical postings.
I am not setting up a new database, I've upgraded an existing database, and need to keep the historical data.
I followed one of the answers posted below and it worked for data that was inputted into the database before the upgrade, but now renders newer data with various “ in place of apostrophes, etc.
You can use
$con = mysqli_connect("HOST","DB_USER","PASSWORD","DB_NAME");
$db->set_charset('utf8');
OR
mysql_query('SET NAMES utf8');
Related
This question already has answers here:
strange character encoding of stored data , old script is showing them fine new one doesn't
(2 answers)
How do I see what character set a MySQL database / table / column is?
(17 answers)
UTF-8 all the way through
(13 answers)
Closed 1 year ago.
Short. I am moving a database and webpage. It is now an exact copy but on the webpage it doesnt display the swedish characters correctly.
Example
VÃƑ„RMARE should be VÄRMARE
In the old database it is VÄRMARE in the new it is VÄRMARE
It is an old webpage on an old php version that when i am moving will be a much later php version and a mariaDB.
I think it has to do with the collation in the database for the tables but in phpmyadmin 2.11.8.1 i can't se collation for the columns.
In the head i define
<meta charset="utf-8">
I don't even know where to start troubleshooting.
Any suggestions how to troubleshoot would be amazing for me.
This question already has answers here:
How to make MySQL handle UTF-8 properly
(15 answers)
UTF-8 all the way through
(13 answers)
Closed 5 years ago.
I'm new to php, i made a php user interface with input fields that formulates, prints and execute a query showing the database reply or error.
It usually works fine but when i make a query with accented fields like in
"INSERT INTO `Nave` (`Targa`, `Nazionalità`, `Nome`) VALUES('0', 'italia', 'nave0');"
php successfully creates the query, prints and executes it without any further modifications but it fails saying "Unknown column 'Nazionalità' in 'field list'"
but if i copy/paste the same exact query printed by php into phpmyadmin it works (so obiouvsly the column 'Nazionalità' does exist) what is happening?
Notice that if the php generated query has no fields with accent it works even in php.
Notice also that individually neither my php nor mysql have any issues dealing with accent. so it's NOT a duplicate of How to make MySQL handle UTF-8 properly because that's a mysql individual issues, my database works fine.
EDIT: All the answers so far explained how to fix the database, but the database does works fine!
I do not know how to make it understand that, read more about the question guys...
But the second duplicate suggestion was quite right and there i found my solution which I copy here for convenience of those who will visit this page having the same problem: "$mysqli->set_charset('put here the same charset used in your db');" OR "mysqli_set_charset($link, 'charset');"
Thank for your help.
change your character set of database to UTF-8 by following MySQL query
ALTER TABLE Nave CONVERT TO CHARACTER SET utf8;
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 7 years ago.
I am making an android application that sends some TEXT to server and other people can see those Text but the problem is here when I send the TEXT it looks like this (سلام به همه) in the MYSQL table inside the server and it shows the text like this (???????????) (By the way I am writing the text in Persian) to the people who get the text and also when I add some records manually inside the database it also shows like question marks on the PHONE.
I tried puting database and tables Collation to utf8_general_ci and utf8_persian_ci but it did not work.
How do you send the data to the server, is it via a PHP Service? If so, I once had a problem with Cyrillic and setting the connection itself to UTF8 helped.
Here's the statement if you are using mysqli but I think there's an alternative for PDO as well.
mysqli_set_charset($con,"utf8");
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 7 years ago.
I exported some tables in my mySQL database on my own server (localhost) to a web host using phpMyAdmin. The tables contain swedish special characters, and the CHARSET is set to latin1_swedish_ci. When imported, the characters look correctly in phpMyAdmin of the web host server, but when they are fetched and displayed on the web, there is a question mark (inside a diamond) instead of each special character.
If I update the data by fething the data into a form and then manually replace the question marks with the special characters and submit (thus updating the table), then the updated data shows correctly in the web when fetched.
But if I do the same thing but using the same update form on my own server where the fetched data displays correctly both in phpMyAdmin and web/localhost and setting the post attribute to the insert page on the web server, then that data does not display correctly (on the web).
I.e. this is the opposite problem of that explained in this post.
What might be wrong?
EDIT: As to the suggestion that using "UTF-8 all the way through" might solve the problem: My question more concerns how I might understand why a problem like this can occur. If the data looks ok in phpMyAdmin, does that mean that the problem lies simply in the fetching? Or might there still be something wrong with the data?
You need to ensure the character set is the same across your connection to the database and the web page it is displayed on.
You are best to use UTF-8 all the way.
On your web page you will need something like this:
So the browser knows what to display.
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 9 years ago.
I setup a MySQL table using Collation latin1_swedish_ci.
I have coded my PHP scripts in the UTF-8 character-set. It all worked out well until I discovered that a person entered their first name with a non-swedish character.
The name Helén looked strange in the database but looked OK on the webpages.
My question is, can I simply change the Collation of my table from latin1_swedish_ci to UTF-8?
Will it actually cause any problems?
You can do it by adding
$db->set_charset("utf8"); // MySQL
mb_internal_encoding("UTF-8"); // Set PHP encoding
header("Content-Type: text/html; charset=utf-8"); // Prevent incorrect encoding in Browser
at the top and escaping every parameter using
$param=$db->escape_string($param);
Then MySQL/PHP will handle everything which is encoding-related for you. When you did this, all your stuff will be in UTF-8.
Your problem with the name is probably related to the header() command, that means that the browser choooses another charset than PHP. You can fix your data by doing that:
$data=utf8_encode($data);
If that produces bad results, try this one:
$data=utf8_decode($data);
After that everything should look fine.
If you want to make UTF8 the default charset, consider adding the following to my.cnf in [mysqld]:
# Set UTF-8 as standard
collation-server = utf8mb4_general_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
That's what I did, I haven't had any issues since a year of development with all what I mentioned in this post.