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;
Related
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');
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 have a database which contains some blocks of text. These text blocks contain extended characters such as: ’ ‘ … “ and ”. When displayed directly to a web page they all show like this: �.
I've tried doing as str_replace to show normal characters, with no luck.
I've tried iconv, which will only work when set to ignore, which makes the punctuation look wrong.
I've tried html_encode, which also doesn't work. (I'm also using the parsedown script to format the text.)
The funny thing is, the website I'm replacing supports these characters fine, so I don't know what I'm doing wrong! (I don't have access to this website, or source code, or database, which is why I'm replacing it!)
Can anyone provide any help??
I just want to stop showing � and start showing proper characters!
Thanks to the above linked article, this issue is now resolved.
I firstly changed the collation of all of my tables as follows:
Specify the utf8mb4 character set on all tables and text columns in
your database.
Then in my php code where it connects to the database, I added this line:
$CONNECTION -> set_charset('utf8mb4');
All issues resolved! Thanks to all who contributed to my fix!
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)
Insert into a table which has a dash in the name
(4 answers)
Closed 8 years ago.
While inserting data "Jack - Jill" in mysql db, it saving as "Jack †Jill“, my problem is when i tried to display the string in page its showing like "Jack �€� Jill", i am just botherd to display the string properly like "Jack - Jill", i tried have proper charactersets but not much of luck.
make sure you specify the charset used by your page to the database (and all its tables), and the other way around. i.e.:
Give your page a metatag and the script witing to the database a line that either validates that the charset is UTF-8 (example charset), or that it converts the chaarset to UTF-8
and give your database the same property, that it saves and reads data as UTF-8 (i use PHPMyAdmin, if you use such GUI tools too, its just a checkbox away).
hope i pointed you into the right direction