Rhombuses / diamonds with question marks instead of Swedish characters in MySQL
I recently moved the contents of a database from one node to another. And after that I get a strange character, like two rhombuses or diamonds with question marks inside instead of the Swedish symbol รค
.
I had this problem before on the first host and then I added this code and it worked fine
$query1 = "SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'";
$query2 = "SELECT * FROM arkitekturobjekt2 WHERE filnamn='{$namn}';";
$result = $db->query($query1);
$result = $db->query($query2);
If I remove the line with $query1
, I only get one diamond. How can I fix this?
EDIT: This is my code and here the lines are put along with the content from the DB in a loop. I've tested using utf8_encode(string)
around ($row->byggnadstyp)
, but then I get another weird character. But finally I tested to remove strtolower
, then it is perfect, besides, the first character is not small. But I can live with it, but I would be interested to know why I get these diamonds when I use strtolower
. I use it utf8
everywhere and the files are set to utf8 without BOM.
$buildingInfo .= "<p>Byggnadstyp: " . strtolower ($row->byggnadstyp) . "</p>";
source to share
You can try adding this to your mysql config:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
default-character-set = utf8
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
skip-character-set-client-handshake=1
The last line (skip-character-set-client-handshake = 1) may not be needed.
If you don't have access to the config file, you can check this one. It basically boils down to sending a command
SET NAMES 'UTF8';
at the beginning of the connection. This is similar to what you are already doing.
source to share