0
  1. I have a table in MYSQL. It is defined as character set - utf8, collation: utf8_general_ci. The ITEM_TITLE column defined as a varchar.

  2. I have this query:
    UPDATE details SET ITEM_TITLE="★32GB VALUE PACK★ Sony Xperia miro ST23i 4GB Int White with silver" WHERE TaskID=109

  3. The result is that in the column ITEM_TITLE i have a title without the ★ and with "?" instead.

THE QUESTION: What should i do, in order to save "★" in the DB properly?

**I found a solution for SQL server - using Nvarchar and not varchar but there is no such type in MySQL.

Answer: I understood what was the problem and why the solution that worked for someone, didnt work for me. First off all, the default for my DB is charset latin. So i changed it to UTF-8 but it didnt solve the issue. The reason for that is that i had a charset latin for most of the rows. I didnt know that it is set automatically for varchar and doesnt change even when i set the table as UTF-8. So I changed everything to UTF-8 and it works fix.

Thanks for all the help!

Alex
  • 169
  • 1
  • 1
  • 9
  • Can't you store it as the `numeric character reference`? Such as `★` ? – Brett Jan 05 '14 at 15:25
  • Brett - what do you mean "store it as numeric"? How can i store a string as a numeric character? – Alex Jan 05 '14 at 15:37
  • deceze - my character set and my collation - both are UTF-8. But it doesnt help with this character. I am reading the link you added here but i am not sure how it helps me – Alex Jan 05 '14 at 15:39
  • @alex I mean can't you convert the character to it's `numeric character reference` which is `★` and then this should display correctly when output on a html page. – Brett Jan 05 '14 at 15:41
  • Brett: I am saving an Excel file in the DB. Manually. So i cant convert it because i dont know its there... I just want the DB to save the title exactly as it is written in the Excel – Alex Jan 05 '14 at 15:43
  • database collation is utf8_general_ci? – Simone Nigro Jan 05 '14 at 15:43
  • 2
    @Brett Don't store characters as HTML entities in the database. There's no problem storing them as actual characters, which is less of an annoyance later on. – deceze Jan 05 '14 at 15:45
  • deceze - i am very glad that there is no such problem. Can you please tell me how exactly it is done? Since i read couple of links but i still didnt find answer to my problem – Alex Jan 05 '14 at 15:52
  • What *is* the problem? What are you doing exactly and what is happening? – deceze Jan 05 '14 at 16:24
  • I thought i was clear in my question but because of you not understanding, i re-write it. Is it clear now? – Alex Jan 06 '14 at 07:08
  • Can you please show us your connection code and the query you're using for the insert, as well as a `SHOW CREATE TABLE` for the table? Double-check that you're following the practices set forth in the proposed dupe. – Charles Jan 06 '14 at 07:44

1 Answers1

0

There shouldn't be a problem with that. Let's try it out

mysql> CREATE TABLE details (
    ->   id int(11) unsigned NOT NULL AUTO_INCREMENT,
    ->   item_title varchar(255) DEFAULT NULL,
    ->   PRIMARY KEY (id)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO details (item_title) VALUES('★32GB VALUE PACK★ Sony Xperia miro ST23i 4GB Int');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM details;
+----+------------------------------------------------------+
| id | item_title                                           |
+----+------------------------------------------------------+
|  1 | ★32GB VALUE PACK★ Sony Xperia miro ST23i 4GB Int     |
+----+------------------------------------------------------+
1 row in set (0.00 sec)

Therefore you most likely break these characters on the way in/out to/from the database.

peterm
  • 91,357
  • 15
  • 148
  • 157
  • How can i "break these characters before" if what i do is inserting it in MYSQL and receiving a row with ? instead of the symbol? – Alex Jan 06 '14 at 08:33
  • anyway, i created a new table as you did and it is working correctly there. I am loosing my mind. The table is exactly the same, same encoding, same varchar etc... What i need to do now is to save all the data, create exactly the same table and copy it... Hopefully this will work. Can you think of any reason how this situation can be possible? – Alex Jan 06 '14 at 08:37