1

Table:

CREATE TABLE `test` (
  `f` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Just after connection I send following SQL:

SET NAMES utf8;

Then SQL:

INSERT INTO `test` (`f`) VALUES ("с😊с-е в терновнике");

As a result in the table I have 1 record with value "с" just up to 😊 sign. Is there a chance to correctly handle all such symbols? All this done from PHP if this matters.

2
  • what does a select length(f) from test say? If it's 1, then your text really is truncated. If it's bigger, then your string is really in there, and you're doing something wrong upon retrieving it. Commented Apr 17, 2014 at 16:27
  • select f, length(f) from test gives length(f) = 2. 2 seems to be equal to 1 char 1 utf8 is multibyte Commented Apr 17, 2014 at 16:44

1 Answer 1

3

That character is Unicode Character 'SMILING FACE WITH SMILING EYES' (U+1F60A).

U+1F60A is in plane 1, the Supplementary Multilingual Plane, but MySQL's utf8 supports only plane 0, the Basic Multilingual Plane. So you'll have to use utf8mb4.

That symbol is also not widely supported in fonts, so you may have a hard time displaying it.


Re your comment, here's a demonstration of filtering out characters beyond the basic plane.

<?php

$str = "с😊с-е в терновнике";
$str = preg_replace('/[^\x{0000}-\x{ffff}]/u', '', $str);
echo $str . "\n";

But if it wasn't clear from my answer above, MySQL does support the supplemental plane in utf8mb4.

Sign up to request clarification or add additional context in comments.

3 Comments

Is there a nice way to remove all chars that mysql does not support using PHP. Or perhaps you can give me a list of such chars?
this question might be relevant.
@Vatev,thanks, both answers on that question are interesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.