1

How can I insert the tulip symbol () into the table column.

I am using PHP 5.3.x and using PDO for db operations, I tried setting various charsets like utf8, utf8mb4 but no use. When I use utf8 it said "Incorrect string value..." and while using utf8mb4 tulip symbol was replaced to "?".

I tried all these options PHP PDO: charset, set names?

$sql = new PDO(MySQL::DRIVER . ":host=host;dbname=db;charset=utf8",
                            MYSQL_USER,
                            MYSQL_PASSWORD,
                            array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); // or utf8mb44
$sql->exec("set names utf8"); // or utf8mb44
$sql->exec("SET CHARACTER SET utf8"); // or utf8mb44
Community
  • 1
  • 1
Garfield
  • 2,487
  • 4
  • 31
  • 54
  • 1
    `utf8mb4` looks like what you want. Where does the symbol come from, how are you encoding it? – Pekka May 16 '13 at 14:54
  • I get from this site https://foursquare.com/kbells130. there you could find name "Kaylya". I do scrape it and send it to db without encoding anything. since i don want encode it. – Garfield May 16 '13 at 14:59
  • FYI, this symbol can be visible in IE10. chrome & firefox shows it as a square. – Garfield May 16 '13 at 15:00
  • @codelover I'm looking at that symbol right now in FF20/windows. – jimmy May 16 '13 at 15:09
  • @jimmy anyhw pls help me to fix – Garfield May 16 '13 at 15:12
  • @codelover could it be that your browser isn't displaying it correctly, even though the database can store it? if you run phpmyadmin for example, in IE10, is there a difference? – jimmy May 16 '13 at 15:19
  • I could see only '?' (utf8mb4) when I see it in phpmyadmin thru IE10 or whatever. – Garfield May 17 '13 at 06:47

1 Answers1

0

The PHP file you're sending it the character in needs to be encoded as UTF-8, and of course the database table needs to be utf8mb4 as Adder points out.

Also, your database connection needs to be explicitly set to utf8mb4 - why not do that straight away when connecting to the database?

$sql = new PDO(MySQL::DRIVER . ":host=host;dbname=db;charset=utf8mb4", ...

Essentially, the advice given in UTF-8 all the way through applies - just replace utf8 by utf8mb4 on mySQL's side.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • I have included ;charset=utf8mb4" still symbol got replaced to "?". My table's & col's charset are utf8mb4 – Garfield May 16 '13 at 15:13
  • @codelover have you checked your file? What happens if you output the symbol from your file into the browser - do you see the right character? – Pekka May 16 '13 at 15:15
  • It prints "\ud83c\uddfa\ud83c\uddf8". – Garfield May 17 '13 at 06:49
  • Well, that's your problem then. Why is it in that form? What exactly is your code? – Pekka May 17 '13 at 06:49
  • My code is just read the txt frm a webpage(like scraping) and sends it to database. while reading txt I got such chars :( – Garfield May 17 '13 at 06:52
  • 1
    You'll need to add more info about what you're doing, and show some code. There's no way for the character to show up in that form unless you're doing something to it (like `json_encode()`) – Pekka May 17 '13 at 06:53
  • Just how could I scrape your name"Pekka 웃" frm this page and store it in db as it is? thats wat I want.:) – Garfield May 17 '13 at 06:54